简体   繁体   中英

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). the collection view should scroll vertically (like a regular tableview does), but it should page horizontally across the content.

I do have the custom layout working except for the paging. Currently, the collectionView will just scroll horizontally. I'm unsure how to implement the paging correctly.

If I just set pagingEnabled on the collectionView, it has no effect. I suspect that the scrollview needs to be told what the width of a page is..?

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. Otherwise, you need to create the paging effect yourself using the UIScrollView delegate methods and animating to offsets yourself after a certain threshold

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