我有 UIViewController,它扩展了 UICollectionViewDataSource、UICollectionViewDelegate、UICollectionViewDelegateFlowLayout。
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
self.extendedLayoutIncludesOpaqueBars = true
}
没有调用 UICollectionviewDelegate 和 DataSource 方法,因此 UICollectionview 看起来是空的。即使我调用重新加载数据,仍未调用 DataSource 方法。
当我删除最后一行时,除了 viewController 下方有空间外,一切正常。
最佳答案
edgesForExtendedLayout
Basically, with this property you set which sides of your view can be extended to cover the whole screen. Imagine that you push a UIViewController into a UINavigationController, when the view of that view controller is laid out, it will start where the navigation bar ends, but this property will set which sides of the view (top, left, bottom, right) can be extended to fill the whole screen.
你需要设置这两个中的一个
self.edgesForExtendedLayout = UIRectEdgeNone;
self.automaticallyAdjustsScrollViewInsets = NO;
或
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = YES;
也许它会对你有所帮助。
关于ios - 当 extendedLayoutIncludesOpaqueBars 设置为 true 时,UICollectionView 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34176097/