I have a paged UICollectionView, with one cell per page. However, my UICollectionViewCells are slow to render (third party library, no options there). So as an optimisation, i need to pre-render the cells to the left and right of the current page, so scrolling is smooth.
What i've done is, inside my custom UICollectionViewLayout, is outset the passed rect by 1 point before checking to see which cells' UICollectionViewLayoutAttributes should be returned, see here:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
CGRect outsetRect = CGRectInset(rect, -1, 0);
return [_myAttributes filter:^BOOL(UICollectionViewLayoutAttributes *attribs) {
return CGRectIntersectsRect(attribs.frame, outsetRect);
}];
}
This works as expected. However, when the actual UICollectionView does its thing, it seemingly ignores the offscreen cells and calls cellForItemAtIndexPath
only for the first cell, not the cell to the right (or left).
Any ideas what is going on? Thanks