Reputation: 81
I am implementing CollectionView with custom layout. It have vertical scrolling. I want to make that some cells will be sticked to the top while scrolling like section header in tableView.
The idea is to create day collectionView with time. And while user will be scroll thought time the current hour will be sticked to the top(if it will be not visible and hidden by top). It will be only if the current hour hidden by top, not by bottom. And the other items should be scrollable like usual. I think that I should not use supplementaryViews here
Is it possible and how can I do it?
Upvotes: 0
Views: 735
Reputation: 1349
You need to override shouldInvalidateLayoutForBoundsChange
so it returns YES
. This means layoutAttributesForSupplementaryViewOfKind
and layoutAttributesForElementsInRect
are called when the UICollectionView
is scrolled, and in there you can then calculate proper frames for your views, including the sticky views. If you have a complicated UICollectionView
, this may lead to bad performance, but as far as I know it's the easiest way to do this for now. Your other bet is looking at invalidation contexts, but they're quite badly documented. If you still want to experiment with those, you could take a look at Using Invalidation Contexts for UICollectionViewLayout
Upvotes: 1