简体   繁体   中英

UICollectionView horizontal paging with UIPageController

not very experienced with collection view paging so I'd need a small help. Im having 6 cells split into 3 pages with UIPageController. Would you suggest having Container View with Collection View & Page Controller inside? Not sure if that would work. Here is how it should look like:

collection view design

Thanks in advance

If you feel that the design may change by grouping two blocks (those rounded square with dash), you'd rather go with UIPageController. Because it will be easier to change the layout page by page.

If you feel that the blocks will always have this size but their order may change or some may disappear, go with UICollectionView. You'll have to design the blocks one by one but you'll get more flexibility to arrange them.

Why use a page view controller? That is designed to display and manage multiple UIViewControllers .

You would be better using a UICollectionView and creating a custom UICollectionViewLayout subclass (actually, you only need to subclass UICollectionViewFlowLayout for this).

Then you can implement the method - targetContentOffsetForProposedContentOffset: to implement the paging of your content.

There are multiple StackOverflow questions about implementing this method. Any of them should be able to help you.

Hope that's of some use.

EDIT

The method I mentioned accepts a content offset point. This is where the content will slow down and stop scrolling after the user lets go of the screen after swiping.

This method will take that target content offset and find the nearest content offset to it that displays a full page properly (ie so that you have your two cells in the screen properly).

The scroll view will then change the animation and decelerate so that it stops on that point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM