每个第一个单元格应该是集合视图的宽度,接下来的2应该是其大小的一半。
它并不重要,因为问题是collectionView.frame.width返回错误的值。
如果我检查iPhone 5上的view.frame,那就是iPhone 6应该拥有的那个:
▿ size : (375.0, 667.0)
- width : 375.0
- height : 667.0
在iPhone 5上,宽度应为320,高度为568。
我还尝试在viewDidLayoutSubviews中打印视图的宽度,但结果相同。
在iPhone 6上,一切正常。问题也出现在iPhone 6 +上。
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if indexPath.row % 3 == 0 {
return CGSize(width: collectionView.frame.width, height: 390)
}
return CGSize(width: collectionView.frame.width / 2 - 4, height: 335)
}