Get the sum of all collectionViewCells' heights inside a CollectionView

泄露秘密 提交于 2019-12-13 02:45:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!