Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top