如何以特定速度自动滚动UIScrollView? [英] How do i make a UIScrollView scroll automatically at a certain speed?
问题描述
我正在使用touchesBegan和touchesMoved来跟踪用户的互动,因此我可以看到用户触摸屏幕的位置。我想要做的是当他们将手指移动到屏幕的最后20个像素时,让UIScrollView scroll1向下滚动。但是我如何定义速度?肯定会有一段时间声明会过快地执行它,并且UIView动画会将它移动到某个地方但只有一次。
I am using touchesBegan and touchesMoved to track a user's interaction, so I can see where the user has touched the screen. What I want to do is when they take their finger to the last 20 pixels of the screen, have the UIScrollView scroll1 to scroll down. But how do i define a speed? Surely a while statement would do it far too rapidly, and a UIView animation would move it to a certain place but only the once.
推荐答案
您可以通过以下代码执行此操作:
You can do this by the following code :
[UIScrollView beginAnimations:@"scrollAnimation" context:nil];
[UIScrollView setAnimationDuration:REQUIRED_ANIMATION_DURATION];
[scroll setContentOffset:CGPointMake(REQUIRED_DISTANCE_X, REQUIRED_DISTANCE_Y)];
[UIScrollView commitAnimations];
只需将REQUIRED_ANIMATION_DURATION的值设置为您想要的任何时间间隔。较小的时间间隔意味着更快的速度。
Just set the values of REQUIRED_ANIMATION_DURATION to whatever time interval you want. A smaller time interval will mean faster speed.
这篇关于如何以特定速度自动滚动UIScrollView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!