问题
有时候,如果cell的尺寸有小数部分,系统会尝试进行四舍五入,导致间隙
解决方法:
将丢失的像素补充到第一个cell的宽度上去
let numberOfItems = CGFloat(jigsawItems.count)
let itemWidth = floor(collectionView.bounds.width / numberOfItems)
/// 消除间隙
var gap = 0.0
if indexPath.row == 0 {
gap = collectionView.bounds.width - itemWidth * Double(jigsawItems.count)
}
return CGSize(width: itemWidth+gap, height: collectionView.bounds.height)
文章讲述了在UICollectionView中,由于cell尺寸可能带有小数导致的间隙问题,通过计算并补充第一个cell的宽度来消除间隙的方法。

2万+

被折叠的 条评论
为什么被折叠?



