问题描述
我正在使用UIScrollView并使用scrollRectToVisible:动画
这对我来说很好。
但是我想慢慢滚动到某个位置,以便用户可以注意到这个效果。
是否有可能。
I'm using UIScrollView and using scrollRectToVisible:animatedThis is working fine for me.But I want to scroll to a location slowly so that user can notice the effect.Is it possible.
我正在尝试以下代码,但没有成功。
I'm trying the following code, but didn't succeed.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:2.0];
[scrlView scrollRectToVisible:<<some cgrect>> animated:YES];
[UIView commitAnimations];
推荐答案
解决方案实际上非常简单。如果您使用 [scrollView scrollRectToVisible:frame animated:YES]
,scrollview将启动它自己的动画,因此为了使用您的持续时间制作动画,您必须使用动画中的[scrollView scrollRectToVisible:frame animated:NO]
。
The solution is actually pretty easy. If you use [scrollView scrollRectToVisible:frame animated:YES]
the scrollview will start it's own animation, so in order to animate with your duration you have to use [scrollView scrollRectToVisible:frame animated:NO]
within your animation.
换句话说:这样可行。
[UIView animateWithDuration:3
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ [scrollView scrollRectToVisible:frame animated:NO]; }
completion:NULL];
这篇关于iphone - UIScrollview - 带有慢动画的scrollRectToVisible的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!