【发布时间】:2018-11-29 11:03:32
【问题描述】:
使用UICollectionView flow delegate,我正在尝试完成此操作,但我仍然需要删除两个单元格区域中的巨大间距。
我的代码:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if indexPath.row == 0 || indexPath.row == 5 {
return CGSize(width: (getWidth()/2) , height: (getWidth()/2))
}
return CGSize(width: (getWidth()/4) , height: (getWidth()/4))
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
预期:
【问题讨论】:
-
你的getWidth函数是什么
-
你需要创建你的自定义 collectionViewLayout 来获得类似的东西。我认为开箱即用的布局是不可能的
-
尝试 BSJ 促销代码
-
raywenderlich.com/… 这会对你有所帮助。
-
问题似乎在你的 getWidth() 函数中检查它。或者可能在您的图像约束中不是 0
标签: swift uicollectionview uicollectionviewflowlayout