Should be possible to customise visible bounds UICollectionView uses for loading cells

Number:rdar://36248287 Date Originated:01-Jan-2018 06:59 pm
Status:Open Resolved:
Product:iOS + SDK Product Version:11.2
Classification:Enhancement Reproducible:Always
This is a request for an alternative solution to the same problem as 36248271. I’ll repeat the problem:

My app shows a collection view where the user scrolls in discrete pages. At any time you can see a bit of the pages to the left and right on the sides. In other words, the paging distance is slightly less than the width of the collection view.

In a scroll view that isn’t a collection view, you can achieve this effect by disabling clipsToBounds and making the scroll view the width of a page but leaving space clear on each size. This does not work for a collection view because UICollectionView uses its bounds to determine which cells to display and when they can be removed and reused.

My solution is to disable scrolling in the collection view and add a hidden paging scroll view with the width of a page, then move the hidden view’s pan gesture recogniser to the collection view. Then whenever the hidden view scrolls set the content offset of the collection view. This works very well but does make my code a bit more complex.

Alternative proposed solution:

UIKit could provide API to set what a UICollectionView uses for the visible bounds. For my problem I could make the collection view the paging width (less than the width of the container), set it to not clip to bounds, then use this hypothetical API to set the visible bounds to a greater width that fills the container.

This would also be very useful for the case of a collection view inside another scroll view. In that case you want to make the bounds’ size of the collection view equal to its contentSize. Then the visible bounds of the collection view would match the visible bounds in the outer scroll view. However that might be better done by a way to ask UICollectionView to derive its visible bounds from a containing scroll view.

Steps to Reproduce:
Try to make an app with a paging collection view where you can see the edges of the pages on each side.

Expected Results:
Should be easy, such as a property to set what the collection view uses for its visible bounds.

Actual Results:
Have to use workarounds like not clipping to bounds, or creating a hidden scroll view of the desired paging.




Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!