Is there a way to change how quickly scrollRectToVisible animates when scrolling a UIScrollView?
Asked
Active
Viewed 2,849 times
6
-
1possible 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 Answers
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];
-
3This however, does not call -scrollViewDidScroll: delegate methods. – iamjustaprogrammer Mar 05 '14 at 00:21
-
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