Independent scrolling for each section of a UICollectionView?

MikeV picture MikeV · Jan 8, 2013 · Viewed 9.4k times · Source

Is it possible to use UICollectionView to build a layout where each section can be independently scrolled? For example, imagine 20 rows of images, where each row could be scrolled independently horizontally to reveal more images offscreen (without scrolling other rows in the process); and the entire view could be scrolled vertically to reveal more rows.

I believe something like this could be implemented with several instances of UICollectionView inside a UIScrollView; however, it'd be great to leverage UICollectionView for inserting/moving sections.

I suspect this isn't practical since UICollectionView is a subclass of UIScrollView; but perhaps this can be done with a custom UICollectionViewLayout?

Answer

TheBasicMind picture TheBasicMind · Jan 11, 2013

You can put multiple UICollectionViews in table cells. The table scrolls vertically. The collection views can be configured to scroll horizontally. I'm doing this on a complex layout and it works well. One constraint to consider is it is much more difficult to do animations that need to move from one table cell to another and you can't use a neat single change of collection view layout to animate all the items in your table view. But if these constraints aren't a problem then this is a relatively easy solution.