4

Is there any way to reduce the speed of scrolling in the UIScrollView, I tried to use scrollRectToVisible: animated: NO to accomplish this (by setting the animation to NO) but seems it's not the right way.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
leCon
  • 41
  • 1
  • 1
  • 2
  • Possible duplicate of http://stackoverflow.com/questions/2017524/change-uiscrollview-scroll-speed http://stackoverflow.com/questions/3719753/iphone-uiscrollview-speed-check – Krishnabhadra Apr 28 '11 at 08:51
  • 1
    No, sorry this is my first post! My post is about the scrolling speed! – leCon Apr 28 '11 at 08:55

2 Answers2

8

You can use a simple uiview animation to do that..

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2];
[scrollview scrollRectToVisible:rect animated:NO];
[UIView commitAnimations];

that's the only way I am aware of.

ios 4 way (this will not work on iphones still running 3.x) :

[UIView animateWithDuration:2 animations:^(void){
    [scrollview scrollRectToVisible:rect animated:NO];
}];
Bastian
  • 10,403
  • 1
  • 31
  • 40
  • Thanks Bastian, but this doesn't work at all! and Apple discourage using the method : `setAnimationDuration` [http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html] – leCon Apr 28 '11 at 08:59
  • that depends... the new functions won't work on a device still running 3.x os, so if you want to support all ios devices you have to use them. However I added the "new" way to my answer. – Bastian Apr 28 '11 at 09:08
  • No, Bastian is definitely right. You just have to adapt his sample to your code. – Steven Kramer Apr 28 '11 at 09:14
  • i Was using this : `[scrollViewPaging scrollRectToVisible: currentFrame animated: no]`, how can i adapt this? – leCon Apr 28 '11 at 09:17
  • I just tried it in my code. It won't automatic scroll to make a rect visible.. you have to put the point of the origin of the rect in. – Bastian Apr 28 '11 at 09:17
  • you can simply use the same function with animated:NO ... it works in my sample – Bastian Apr 28 '11 at 09:20
  • Thanks, this work only when scrolling outside my current frame(my scrollView), when i scroll the scrollView this code has no effect. – leCon Apr 28 '11 at 09:41
7

I know this is not exactly what you asked for but it may help you to set deceleration rate with UIScrollView property

@property(nonatomic) float decelerationRate
Damien Debin
  • 2,812
  • 25
  • 41