I have a uicollectionview using flow layout that has a supplementary header view which is a view that I only sometimes want to display. So basically I want to have a button that will, when clicked, remove the supplementary view from the collection view and also re-place all the items in the collection view with the consideration that the header is gone. Is this possible? I've tried it repeatedly in many ways. Changing the reference header size, changing my answer to the delegate method for the header size, invalidating the layout, reloading the data etc etc etc. What am I missing?
I just ran a test. I think that it's related to using UIDynamics, what is it in UIDynamics that would override my delegate response for header section reference size?
In your delegate's layout methods return the appropriate size for whatever state you're interested in:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
if (self.headerVisble) {
return CGSizeMake(collectionView.bounds.size.width, 30.0f);
}
else {
return CGSizeZero;
}
}
Then when you need to update the layout call:
[collectionView.collectionViewLayout invalidateLayout];
The collection view will ask the Layout object for new info which will in turn ask your delegate. I believe it will animate the change too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With