ios 强制 UICollectionView 停止滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23640733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Force UICollectionView to stop scrolling
提问by Pétur Ingi Egilsson
A user performs a quick swipe gesture to make a UICollectionView start scrolling (it will gradually come to an halt).
用户执行快速滑动手势以使 UICollectionView 开始滚动(它将逐渐停止)。
How can I programmatically force the scrolling to come to an immediate stop? To clarify, I want to allow the deceleration but I need to be able to stop it in code.
如何以编程方式强制滚动立即停止?澄清一下,我想允许减速,但我需要能够在代码中停止它。
回答by haifacarina
Try this one. Worked for me. :)
试试这个。为我工作。:)
self.collectionView.scrollEnabled = NO;
回答by liamnichols
Have you tried the following?
您是否尝试过以下方法?
[self.collectionView setContentOffset:self.collectionView.contentOffset animated:NO];
the contentOffset
property is constantly updated as the collectionView scrolls (even via animation) so at the time of calling the above, it should hopefully force the collectionView to stop its existing animation.
contentOffset
当 collectionView 滚动(甚至通过动画)时,该属性会不断更新,因此在调用上述内容时,它应该有希望强制 collectionView 停止其现有动画。
回答by Rakesh Gujari
For Swift 3:
对于 Swift 3:
collectionView.isScrollEnabled = false
回答by idanuda
if you have the pagingEnabled
and scrollEnabled
properties set to true
than this should work:
如果您将pagingEnabled
和scrollEnabled
属性设置为true
比这应该工作:
self.collectionView.scrollEnabled = false
self.collectionView.pagingEnabled = false
回答by Tommy Devoy
Adopt the following scrollViewDelegate
method to pick up when the user lets go of dragging the collectionView.
scrollViewDelegate
当用户松手拖动collectionView时,采用以下方法进行拾取。
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset;
You can then just create your own animation block to set whichever speed/final destination you think looks best using the contentOffset
property.
然后,您可以创建自己的动画块来设置您认为使用该contentOffset
属性最好看的任何速度/最终目的地。