I'm not 100% sure on this, but it looks like once you scrolled down far enough, the header's original position was no longer located inside the rect
argument. This caused the header's layout attributes to not be included in the attributes
array you iterated over in in the for
loop, resulting in the layout position no longer being adjusted to its "sticky" position at the top of the screen.
Try adding these lines right before the for
loop to add the sticky header's layout attributes to the attributes
array if they are not already there:
NSIndexPath *stickyHeaderIndexPath = [NSIndexPath indexPathForItem:0 inSection:SectionWithStickyHeaderIndex]; UICollectionViewLayoutAttributes *layoutAttributes = [self layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader atIndexPath:stickyHeaderIndexPath]; if (![attributes containsObject:layoutAttributes]) { [attributes addObject:layoutAttributes]; }