I'm using UICollectionReusableView
as a header of UICollectionView
section. I enabled "sticky headers" with:
let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout
layout?.sectionHeadersPinToVisibleBounds = true
I'm inserting new sections to collection with:
collectionView.performBatchUpdates({
self.collectionView.insertSections(IndexSet(integersIn: collectionView.numberOfSections...viewModel.numberOfSections - 1))
}, completion: nil)
If the insertion happens when collection is overscrolled (bounce is enabled), header will disappear for while (see GIF below). How can I avoid this behaviour?
I am using iOS 12.1.4 but same issue happens also on iOS 11.x and 12.x simulators.
The problem doesn't happen if bounce effect is turned off but I want to keep it on for smoother scroll feeling. I tried invalidate layout before/after update with no result. Thanks for advices.
EDIT (02/26/2019)
Workaround: Wrapping the insertion to performWithoutAnimation
block solve header disappearing but obviously disable reload animation.
UIView.performWithoutAnimation {
collectionView.performBatchUpdates({
self.collectionView.insertSections(IndexSet(integersIn: collectionView.numberOfSections...viewModel.numberOfSections - 1))
}, completion: nil)
}