Utilize iOS 8 self-sizing cells to find out cell dimensions
iOS 8 provides a new self-sizing API for CollectionView and CollectionViewCells. It lets cells determine their own height, based on the content that they're about to load.
This dance involves various methods like
preferredLayoutAttributesFittingAttributes:(on the cell)shouldLayoutAttributesFittingAttributes:(on the layout)invalidationContextForPreferredLayoutAttributes:withOriginalAttributes:(on the layout)
The waterfall layout could make use of this dance and harness the self-sizing height measurement, whilst demanding that width be fixed.
Try this solution http://stackoverflow.com/questions/25753373/ios-8-gm-does-not-update-constraints-on-collection-views
After having a play around I'm not sure this is going to be possible, or the entire implementation may have to be overhauled.
By the time the self sizing cell calculates it's size (I think that's through preferredLayoutAttributesFittingAttributes:), prepareLayout has already been run, so there may be discrepancies in the frames if we're to use the new size, and the entire thing will need invalidating leading to a never ending cycle of the frames being wrong. Unless we could somehow cache the self size value to an index path and use that value if it exists.
Argh, I don't know, brain's dead, will have a crack another time.
Caching the size based on the index path is a good idea. As you calculate a new size, only the cells below that cell need to be invalidated (and only their y positions, not their sizes). We do cell size caching based on index path in RZCellSizeManager. The only reason I'm not using it with this layout is because it doesn't play nice with trait collections, which is what led me to look into self-sizing cells.
For me worked approach demoed here https://github.com/honghaoz/Dynamic-Collection-View-Cell-With-Auto-Layout-Demo. It is still produces heavy computations (and CPU spikes) on each realodData call.
Not sure if caching sizes will help in cases when content is rebuilt after user changes search criteria, sort order etc.
@ikovalisko You were able to get CHTCollectionViewWaterfallLayout working with cell sizes from auto-layout? Were your cells defined in XIBs or as prototype cells in a storyboard? I've got the latter and can't get things working.
Any movement on this since?
We have never been able to get the cells to not have broken constraints, and fast-forward years later self-sizing cells are the default that collection views utilize (opt-out by default)
Would be great to know that we can use this library still