简体   繁体   English

SWIFT中CollectionView内部的单元格自动滚动

[英]Automatic Scroll of Cell inside CollectionView in SWIFT

How can I scroll inside a collection view such that I will always see one cell at a time, occupying the whole screen? 如何在集合视图中滚动,以便始终每次看到一个单元格并占据整个屏幕? Like what you do when browsing individual photos in your iPhone's gallery. 就像您在iPhone的图库中浏览单张照片时所做的一样。 Let's say: 比方说:

(cell 1) |space| (单元格1)| space | (cell 2) (单元格2)

when I scroll to the left and the space position is less than half of screen width, automatically, (cell 1) should go back to its position and occupy the screen. 当我向左滚动并且空格位置小于屏幕宽度的一半时,(单元格1)应自动回到其位置并占据屏幕。 But when I scroll left and space is greater than screen width, (cell 2) will automatically occupy the screen and pushing the (cell 1) away.. 但是,当我向左滚动并且空间大于屏幕宽度时,(单元2)将自动占据屏幕并推开(单元1)。

How can I achieve that? 我该如何实现?

The behaviour you're looking for is called paging , but if you want a space between cells then you will need to use a custom layout ( UICollectionViewLayout subclass) and implement - targetContentOffsetForProposedContentOffset:withScrollingVelocity: . 您正在寻找的行为称为分页 ,但是如果您想要在单元格之间UICollectionViewLayout出空间,则需要使用自定义布局( UICollectionViewLayout子类)并实现- targetContentOffsetForProposedContentOffset:withScrollingVelocity: This tells the collection view where to come to a halt after the user stops interacting. 这告诉收集视图,在用户停止交互之后该停止。

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

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