美文网首页
UICollectionView报错:the item heig

UICollectionView报错:the item heig

作者: 生命不止运动不息 | 来源:发表于2021-04-01 09:44 被阅读0次

今天遇到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的大小)。

错误示例:


itemSize大小大于内容大小

解决方法:

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


image.png

注意:关闭自动调整sectionInsets

if #available(iOS 11.0, *) {
      collectionView.contentInsetAdjustmentBehavior = .never
}
else{
      self.automaticallyAdjustsScrollViewInsets = false
}

参考文章:https://blog.csdn.net/wm9028/article/details/79614455

相关文章

网友评论

      本文标题:UICollectionView报错:the item heig

      本文链接:https://www.haomeiwen.com/subject/opozhltx.html