我正在覆盖 UICollectionViewDelegateFlowLayout 的 sizeForItemAt 方法。我想做的只是在我在某个部分时计算大小,然后回退到其他部分的默认流布局行为。
我不完全确定如何去做,因为我没有子类化我不能只使用超类实现。
一个正确方向的观点将不胜感激。
编辑
我想systemLayoutSizeFitting
如下所示使用,但sizeForItemAt
调用时未创建单元格。
guard indexPath.section == sectionNumber else {
// This always returns nil as the cell hasn't been created when sizeForItemAt runs
guard let cell = collectionView.cellForItem(at: indexPath) else {
return .zero
}
return cell.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
}
return someCalculatedCGSize
我尝试创建自己的布局子类,但遇到了同样的问题,我有两个全宽单元格,自动布局提供约束,然后是网格布局,我在其下方手动计算大小。所以我想回到我的约束条件,为前两个单元格提供大小。