简体   繁体   English

使用UIPageController的UICollectionView水平分页

[英]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. 我有6个单元格,使用UIPageController分为3页。 Would you suggest having Container View with Collection View & Page Controller inside? 您是否建议将Container View与Collection View&Page Controller一起放在内部? 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. 如果您认为可以通过对两个块进行分组来改变设计(那些带有短划线的圆角正方形),则最好使用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. 如果您认为这些块将始终具有此大小,但是它们的顺序可能会更改或有些可能会消失,请使用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 . 旨在显示和管理多个UIViewControllers

You would be better using a UICollectionView and creating a custom UICollectionViewLayout subclass (actually, you only need to subclass UICollectionViewFlowLayout for this). 您最好使用UICollectionView并创建一个自定义UICollectionViewLayout子类(实际上,您只需要为此子类UICollectionViewFlowLayout )。

Then you can implement the method - targetContentOffsetForProposedContentOffset: to implement the paging of your content. 然后,您可以实现方法- targetContentOffsetForProposedContentOffset:来实现内容的分页。

There are multiple StackOverflow questions about implementing this method. 关于实现此方法,存在多个StackOverflow问题。 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. 然后,滚动视图将更改动画并减速以使其在该点停止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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