我正在使用 touchesBegan 和 touchesMoved 来跟踪用户的交互,因此我可以看到用户触摸屏幕的位置.我想要做的是当他们将手指移到屏幕的最后 20 个像素时,让 UIScrollView scroll1 向下滚动.但是我如何定义速度?当然,while 语句会执行得太快,而 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 以一定的速度自动滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!