获取CollectionView内部所有collectionViewCells的高度之和
我在CollectionView单元格类中创建了一个CollectionView.
I have a CollectionView created inside CollectionView cell class.
问题是,我无法获得生活在第一个collectionView中的CollectionView的完美大小,以适应所有单元格的大小(如果有的话).
The thing is I can't get the CollectionView that lives inside the first collectionView get the perfect size to fit all cells' sizes if any.
第一级注释行是第一个CollectionView单元格,其中包含第二级注释(contentView为蓝色,包含单元格的collectionView为红色)
First level comments Line is the First CollectionView Cell, enclosing the second level comments(contentView is blue and the collectionView holding the cells is red)
我正在使用约束来设置第二个collectionView的高度.现在基本上已修复.
I am using constraints to set the second collectionView height. It's basically fixed now.
我知道如何使注释单元格具有动态高度,但是如何使第二个collectionView具有动态高度以适合所有单元格(如果有)?
I know how to make the comments cells have dynamic height, but how can I make the second collectionView have dynamic height to fit all cells if any?
可能的解决方案,使用以下方法做
Possible solution, doing something with:
for cell in collectionView.visibleCells as! [MyCellClass] {
let sumOfAllCells += cell.frame.height
}
var height: CGFloat = 0
collectionView.visibleCells.forEach({ height += $0.bounds.height })