我将这个问题作为这个问题的一个分支
ViewCells 上的自动调整大小非常完美。但是当我重新加载我的 CollectionView 时,高度返回 1。
代码如下。
extension SaleViewController: CollectionViewFlowLayoutDelegate{
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
guard let flowLayout = self.myCollectionView.collectionViewLayout as? CustomLayout else {
return
}
flowLayout.invalidateLayout()
}
func height(at indexPath: IndexPath) -> CGFloat {
guard let cell = self.myCollectionView.cellForItem(at: indexPath) else {
return 1
}
cell.layoutIfNeeded()
//get calculated cell height
return cell.systemLayoutSizeFitting(UILayoutFittingCompressedSize).height
}
}
缺少什么或我应该重新考虑什么来保持我的自动高度?
提前致谢。