首页 > 解决方案 > 如何将集合视图和页面视图放在一个场景中

问题描述

我正在创建一个如下所示的屏幕:

屏幕

但问题是,pagedView 需要我的视图控制器继承自UIPagedViewController,而 colleciton 视图需要继承自UICollectionViewController.

有没有办法做到这一点?

标签: iosswift

解决方案


您不必使用UIPagedViewControllerUICollectionViewController使其继承自UIViewController,并且在里面说loadView/ViewDidLoad使用

let pager = UIPagedViewController()
// then add it as a child vc and constraint it's view or set a frame

let collec = UICollectionView(///
// add to view and constraint also

以上也应该是实例变量,因此它们的代表/数据源被保留


推荐阅读