【发布时间】:2023-03-05 08:22:01
【问题描述】:
我尝试按照这个解决方案 (How to determine height of UICollectionView with FlowLayout) 来确定我的 UICollectionViewLayout 的大小,以便相应地调整单元格的大小。我下面的代码调用了collectionViewContentSize,它在被调用时会抛出一个错误:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let frameWidth = collectionViewLayout.collectionViewContentSize.width
let maxCellWidth = (frameWidth) / (7.0/6.0 + 6.0)
let frameHeight = collectionViewLayout.collectionViewContentSize.height
let maxCellHeight = frameHeight
let cellEdge = maxCellWidth < maxCellHeight ? maxCellWidth : maxCellHeight
return CGSize(width: cellEdge, height: cellEdge)
}
错误是线程 1 SIGABRT。
知道为什么这不起作用吗?
【问题讨论】:
标签: swift uicollectionview uicollectionviewlayout