I am trying to implement sticky footers in custom layout (we can’t use flow layout). And there are cases where footer is hidden temporarily.
I am subclassing UICollectionViewLayout
. I have implemented layoutAttributesForElements(in rect: CGRect)
, layoutAttributesForItem(at indexPath: IndexPath)
and layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath)
– so basically all necessary overrides are there.
shouldInvalidateLayout(forBoundsChange newBounds: CGRect)
returns true and shouldInvalidateLayout(forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes, withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes)
returns true if height changes.
in rect
method returns valid footer attributes every time. However, I have noticed a weird animation glitch if I spring load collection view at the top and then fling it fast. Footer will quickly fade away while scrolling together with the content and reappear in right place immediately. When debugging I noticed that finalLayoutAttributesForDisappearingSupplementaryElement
is called for the footer and that would explain why fade animation is triggered.
I have noticed that returning layout attributes where height is set to 0 results in view not getting dequeued, but this is not the case for that footer.
How can i prevent the view from getting into a state where UICollectionView wants to hide it?