I want to be able to set the minimum height of the content size within a UICollectionView, so I can hide/show a UISearchbar, similar to the way it's done on iBooks.
However, I don't want to subclass the layout as I want to keep the standard vertical layout for a UICollectionView.
any ideas?
you can try this quick solution, the search bar will be hidden if you have enough items to fill the screen. Of course you can change the UISearchBar below with any custom view.
another solution which does exactly the same thing is to use supplementary views. I just had a go. Create a subclass of UICollectionReusableView, make sure you set the header reference size on the flow layout
register the supplementary view with collection view
and implement the UICollectioViewDataSource method
And finally after each reload, reposition the collection view at the start of the first item to hide the searchBar/header view.
Tutorials for supplementary views techotopia.com, appcode.com, mobinius
You can do this by subclassing UICollectionViewFlowLayout and overriding the method
Edit: I just realized you said you didn't want to subclass the layout. Anyway, I subclassed UICollectionViewFlowLayout and only modified the collectionViewContentSize method. It kept the standard vertical layout for me.
Edit: https://stackoverflow.com/a/14465485/2017159. Here it says UICollectionViewFlowLayout only supports one direction (vertical or horizontal), so it should be fine?
This is a tweaked version of khangsile's answer. Capping only the dimentions that are actually smaller than the minimum size