今天遇到UICollectionView layout报错问题
The behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
原因:
layout的itemSize的大小大于了 (collectionView的大小 - sectionInset的大小)。
错误示例:

解决方法:
改下item的尺寸。这里我就直接将itemSize的高度减去sectionInset的上下距离了。也就是 -10.

注意:关闭自动调整sectionInsets
if #available(iOS 11.0, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
else{
self.automaticallyAdjustsScrollViewInsets = false
}
网友评论