문제

A user performs a quick swipe gesture to make a UICollectionView start scrolling (it will gradually come to an halt).

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.

도움이 되었습니까?

해결책

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.

다른 팁

Try this one. Worked for me. :)

self.collectionView.scrollEnabled = NO;

For Swift 3:

collectionView.isScrollEnabled = false

if you have the pagingEnabled and scrollEnabled properties set to true than this should work:

self.collectionView.scrollEnabled = false
self.collectionView.pagingEnabled = false

Adopt the following scrollViewDelegate method to pick up when the user lets go of dragging the 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top