当数据源只有1个项目时,UICollectionView不会反弹 [英] UICollectionView doesn't bounce when datasource has only 1 item
问题描述
我有一个带有自定义UICollectionViewFlowLayout的UICollectionView。它水平滚动,一次只显示一个项目(全高)。我有pagingEnabled = YES,所以它坚持页面。
I have a UICollectionView with a custom UICollectionViewFlowLayout. It scrolls horizontally and only shows one item at a time (full height). I have pagingEnabled = YES so that it sticks to pages.
UICollectionView显示特定日期内的照片。我最初有按钮来改变日+/- 1天,但我认为如果用户可以通过第一张或最后一张图像(超过预定阈值)拉动收集视图以改变日期,那将是整洁的。我使用UIScrollView委托方法实现了它,如果集合视图中有2个或更多项,它可以很好地工作。
The UICollectionView shows photos within a particular day. I initially had buttons to change the day +/- 1 day, but I thought it would be neat if the user could pull on the collection view past the first or last image (past a predetermined threshold) to change the day. I implemented this using the UIScrollView delegate methods and it works great...... if there are 2 or more items in the collection view.
这很难描述,但如果只有一个项目,则不允许我拉出项目超出界限。 I.E.它没有反弹。
This is hard to describe, but if there is only 1 item, it doesn't allow me to pull the item past it's bounds. I.E. there is no bounce to it.
我想有这种行为,但我需要先解决这个问题。我想如果我删除了pagingEnabled = YES并使用了targetContentOffsetForProposedContentOffset:proposedContentOffset:withScrollingVelocity,那我可以让它工作但我真的很喜欢分页启用的快速行为。 (它们是相互排斥的)。
I'd like to have this behavior, but I need to overcome this problem first. I'm thinking that if I removed pagingEnabled = YES and used targetContentOffsetForProposedContentOffset:proposedContentOffset:withScrollingVelocity, that I may be able to get it to work but I really enjoy the snappy behavior that paging enables. (They are mutually exclusive).
有关于此的任何想法吗?
Any ideas on this?
推荐答案
UICollectionView
具有 alwaysBounceHorizontal
和 alwaysBounceVertical
属性。将水平设置为YES 确实
。
UICollectionView
has the properties alwaysBounceHorizontal
and alwaysBounceVertical
. Setting the horizontal to YES did
the trick.
这篇关于当数据源只有1个项目时,UICollectionView不会反弹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!