The power of UICollectionView to stop scrolling

The user performs a quick swipe to scroll through the beginning of the UICollectionView (it will stop gradually).

How can I programmatically make the scroll go to an immediate stop? To clarify, I want to allow slowdown, but I need to be able to stop it in the code.

+7
ios objective-c uicollectionview
source share
5 answers

Have you tried the following?

[self.collectionView setContentOffset:self.collectionView.contentOffset animated:NO]; 

The contentOffset property contentOffset constantly updated as the collection scrolls through the contentOffset (even through the animation), so during the call to the above, it should hope to make collectionView stop the existing animation.

+20
source share

Try it. Worked for me. :)

 self.collectionView.scrollEnabled = NO; 
+25
source share

For Swift 3:

 collectionView.isScrollEnabled = false 
+2
source share

Adopt the following scrollViewDelegate method to select when the user translates a drag and drop collection.

 -(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset; 

Then you can simply create your own animation block to set which speed / destination you think is best using the contentOffset property.

+1
source share

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

  self.collectionView.scrollEnabled = false self.collectionView.pagingEnabled = false 
0
source share

All Articles