Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Independent scrolling for each section of a UICollectionView?

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?

like image 204
MikeV Avatar asked Jan 08 '13 22:01

MikeV


People also ask

How do I scroll horizontally in UICollectionView?

You need to reduce the height of UICollectionView to its cell / item height and select " Horizontal " from the " Scroll Direction " as seen in the screenshot below. Then it will scroll horizontally depending on the numberOfItems you have returned in its datasource implementation.

How do I stop auto scrolling of UICollectionView by voiceover?

UIScrollViewDelegate. scrollViewDidScroll(_:) A change in the accessibility focus that triggers an automatic scrolling also triggers a call to scrollViewDidScroll(_:) in your UIScrollViewDelegate. Use that to counter the automatic scrolling effect, f.i. by setting contentOffset the way you prefer it.

Is CollectionView scrollable?

CollectionView defines two ScrollTo methods, that scroll items into view.

What is Uicollectionviewflowlayout?

A layout object that organizes items into a grid with optional header and footer views for each section.


2 Answers

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.

like image 55
TheBasicMind Avatar answered Sep 28 '22 04:09

TheBasicMind


This is a pretty common issue that I've needed to solve multiple times, and I've created a UICollectionViewLayout that solves this in a clean way without creating multiple collection views, meaning it supports moving items between sections etc.

https://github.com/joelekstrom/JEKScrollableSectionCollectionViewLayout

like image 35
Accatyyc Avatar answered Sep 28 '22 04:09

Accatyyc