问题
I have a CollectionView created inside CollectionView cell class.
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.
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)
I am using constraints to set the second collectionView height. It's basically fixed now.
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
}
回答1:
var height: CGFloat = 0
collectionView.visibleCells.forEach({ height += $0.bounds.height })
来源:https://stackoverflow.com/questions/56409656/get-the-sum-of-all-collectionviewcells-heights-inside-a-collectionview