我有一个 UIPageViewController,其中包含需要调整的 collectionView 的 contentInset 的 UICollectionViewController。出于各种 UI 布局原因,当这些 UICollectionViewController 出现在 UIPageViewController 中时,我只需要在这些 UICollectionViewController 上使用 contentInset。下面是我尝试调整 collectionView 的 contentInset。
self.viewControllers = [ ViewControllerA(), ViewControllerB(), ViewControllerC()]
for viewController in viewControllers {
if let vc = viewController as? UICollectionViewController, collectionView = vc.collectionView {
collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: bottomContentInset(), right: 0)
}
}
我遇到的问题是只有第一个 View Controller (在第一页上)得到了 contentInsetadjusted,有没有更好的方法来做到这一点
最佳答案
不确定您是否解决了这个问题,但这可能一直在发生,因为只有可见 Collection View 的单元格(在 ViewControllerA
中)被出队。其他 VC 中的 Collection View 单元格可能尚未出列,或者其他 VC 本身可能尚未初始化(不确定您如何实例化 VC)。我要么使用 UIPageViewController
的委托(delegate)方法来设置每个 Collection View 的 contentInset
属性,要么在每个 VC 的 viewWillAppear:
方法中尝试.
关于ios - 在 UIPageViewController 中设置 UICollectionView 的内容插入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30582173/