Deactivate Slow UIScrollView

Is there a way to deactivate the slowdown of a UIScrollView?

I want to allow the user to scroll through the canvas, but I do not want the canvas to continue to scroll after the user lifts his finger.

+36
iphone cocoa-touch uiscrollview
Jul 09 '09 at 18:17
source share
5 answers

This can be done using the delegate method UIScrollView scrollViewWillBeginDecelerating to automatically set the content offset to the current screen position.

For implementation:

  • Assign a delegate to your UIScrollView if you have not already done so.
  • In the .m delegate implementation file, add the following lines of code:

     -(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ [scrollView setContentOffset:scrollView.contentOffset animated:YES]; } 

Voila! No more auto-scrolling.

+63
Aug 6 '09 at 21:08
source share
β€” -

For iOS 5.0 or later, there is a better method than calling setContentOffset:animated:

Implement delegate method scrollViewWillEndDragging:withVelocity:targetContentOffset: in .m file:

 - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { *targetContentOffset = scrollView.contentOffset; } 

Assigning the current offset to targetContentOffset stops the UIScrollView from automatically scrolling.

+38
Oct. 17
source share

You can increase your braking speed very quickly. With infinite speed, he stopped immediately. Try setting the speed for these constants:

 scrollView.decelerationRate = UIScrollViewDecelerationRateNormal; 

and

 scrollView.decelerationRate = UIScrollViewDecelerationRateFast; 

If fast is still not fast enough for you, UIScrollViewDecelerationRateFast is just typedef'ed as a float, so you can just multiply it by 10 or so to speed it up even more.

+20
Jul 09 '09 at 18:22
source share

Just set the decelerationRate property to 0

This will disable the auto scroll property. But keep in mind that user interaction will become bad if the size of the scrollview content is large.

0
Mar 28 '18 at 7:15
source share

Code of the previous version: ↓

scrollView.decelerationRate = UIScrollView.DecelerationRate.fast

Current version 4.2 code: ↓

scrollView.decelerationRate = UIScrollViewDecelerationRateFast

0
Apr 17 '19 at 5:03
source share



All Articles