6

Is there a way to change how quickly scrollRectToVisible animates when scrolling a UIScrollView?

Moshe
  • 57,511
  • 78
  • 272
  • 425
  • 1
    possible duplicate of [UIScrollView scrollRectToVisible at custom speed](http://stackoverflow.com/questions/1558262/uiscrollview-scrollrecttovisible-at-custom-speed) – Sebastian Jan 27 '15 at 22:08

2 Answers2

17

Just set the animation argument to NO and then perform your own animation using the UIView's animation class methods.

[UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
    [scrollView scrollRectToVisible:viewFrame animated:NO];
} completion:nil];
Artrmz
  • 340
  • 2
  • 14
Camsoft
  • 11,718
  • 19
  • 83
  • 120
6

No, not with public methods. The duration is fixed at 0.3 seconds.

There is a private, undocumented API to change the duration:

@interface UIScrollView(UIScrollViewInternal)
-(void)_setContentOffsetAnimationDuration:(NSTimeInterval)duration;
@end

but as all undocumented API, using this will lead to rejection from AppStore.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • Actually, I plan on distributing Ad Hoc, might not be a problem. Where can I find this method defined? Thanks! – Moshe Nov 04 '10 at 21:24
  • @Moshe: It has to be declared manually. You can include the category above to a file that uses it. – kennytm Nov 04 '10 at 21:26
  • Actually, I just called it as `[scrollView _setContentOffsetAnimationDuration:8.0]` and it worked. Just note that if you're using with NSTimer, like me, the animation duration must be larger than the interval for the timer, or it will be jumpy. – Moshe Nov 04 '10 at 21:30