I'm trying to create a sticky supplementary header, which stays on top all the time and won't response to scrolling events. The solutions I found so far still react on bounch scrolling and are fixed using a custom flowLayout, which will probably be the fix for mine issue as well.
The reason I want it this way is that the header is used on other places and should be reusable. I'm hoping this could be solved this way and I don't have to create a separated view.
As I'm doing this in Swift, it would be great to have an example in Swift.
The final solution I found:
Using this custom flow layout it was possible to fix this sticky header:
To create a layout where the headers are sticky like traditional, change this line:
to this line:
Hoping this is useful for others!
Update
Updated to fix a crash (thanks to Robert Atkins!) and some updates to Swift 1.2
tvOS & iOS 9
tvOS and iOS 9 introduced the property
sectionHeadersPinToVisibleBounds
which can be usedSwift 2.2 version tested based on GregP's answer. Greg's code was throwing an unwrap optional error at lastCellIndexPath because the number of section is initially zero. So I moved the numberOfItemsInSection > 0 check up.
Here is a simple solution that works if you only have one section.