This post will explain how to mimic the 'sticky' behaviour of
UITableView headers using a
UICollectionView. To do this we'll implement a subclass of
UICollectionViewFlowLayout that we will then use to tweak the position of header views as the content scrolls.
It's not uncommon to use a
UICollectionView to show a grid of items in a view and use Interface Builder to configure it's to fit a particular phone width. Unfortunately we no longer have a single phone width to worry about and if we use this static layout on a wider iPhone such as an iPhone 6, the standard behaviour of a
UICollectionViewFlowLayout is to increase the spacing between the cells. What is often prefferable is for the collection view's cell size to grow, leaving the gap the same across different device sizes.
iOS 8 adds a new class,
UIPresentationController, that works along-side the classes and protocols introduced in iOS 7 to help us implement custom view controller transitions. I always find it easier to understand a new API by working through an example, so let's build the following transition