[英]UICollectionView - vertical scrollling, horizontal paging with custom layout
I'm trying to implement an iOS collection view which basically should work similar to a table view, but the cells' widths being integer multiples of the collection view's width (eg. 4 times the width). 我正在尝试实现一个iOS集合视图,它基本上应该类似于表视图,但单元格的宽度是集合视图宽度的整数倍(例如,宽度的4倍)。 the collection view should scroll vertically (like a regular tableview does), but it should page horizontally across the content. 集合视图应该垂直滚动(就像常规的tableview一样),但它应该在内容中水平翻页。
I do have the custom layout working except for the paging. 我确实有自定义布局工作,除了分页。 Currently, the collectionView will just scroll horizontally. 目前,collectionView将只是水平滚动。 I'm unsure how to implement the paging correctly. 我不确定如何正确实现分页。
If I just set pagingEnabled
on the collectionView, it has no effect. 如果我只是在collectionView上设置pagingEnabled
,它就没有效果。 I suspect that the scrollview needs to be told what the width of a page is..? 我怀疑需要告诉scrollview页面的宽度是什么......?
Or do I have to do anything weird because there is only one cell/column per row, instead of multiple cells? 或者我必须做任何奇怪的事情,因为每行只有一个单元格/列,而不是多个单元格?
See the image; 看图像; the grey bars are the cells, the blue rect is the collection view frame. 灰色条是单元格,蓝色矩形是集合视图框架。
thanks! 谢谢!
I believe if the collection view item widths are less than or equal to the width of the collection view, then the horizontal paging should work via the pagingEnabled
property. 我相信如果集合视图项宽度小于或等于集合视图的宽度,那么水平分页应该通过pagingEnabled
属性工作。 Otherwise, you need to create the paging effect yourself using the UIScrollView
delegate methods and animating to offsets yourself after a certain threshold 否则,您需要使用UIScrollView
委托方法自己创建分页效果,并在某个阈值后设置动画以自行抵消
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.