开发者

UIScrollView scrollRectToVisible at custom speed

I have a UIScrollView and I'm calling scrollRectToVisible:animated:YES on it. I would like to set开发者_StackOverflow中文版 the speed at which it is animated. Can that be done?


I ended up finding a solution. In my case, the scrolling was animated programmatically after launch, to mimic a slot machine (with 3 horizontal UIScrollViews). Was doing this with the scrollRectToVisible:animated: method.

I got to set a custom speed using UIView's beginAnimation:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:(abs(rMid-pMid)*0.3)];
scrollMid.contentOffset = CGPointMake(rMid*320, 0);
[UIView commitAnimations];

AnimationDuration depends on the distance the scroller has to move between each "drawing".


A modern version with blocks:

[UIView animateWithDuration:1.0 animations:^{
    [self.scrollView scrollRectToVisible:CGRectMake(...) animated:NO];
} completion:^(BOOL finished) {
    ...
}];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜