问题
有时候,如果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)