简体   繁体   English

如何使UIScrollView以一定速度自动滚动?

[英]How do i make a UIScrollView scroll automatically at a certain speed?

I am using touchesBegan and touchesMoved to track a user's interaction, so I can see where the user has touched the screen. 我正在使用touchesBegan和touchesMoved来跟踪用户的交互,因此我可以看到用户触摸屏幕的位置。 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. 我要做的是当他们将手指移至屏幕的最后20个像素时,让UIScrollView scroll1向下滚动。 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. 当然,while语句会做得太快,而UIView动画会将其移动到某个位置,但只能移动一次。

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];

Just set the values of REQUIRED_ANIMATION_DURATION to whatever time interval you want. 只需将REQUIRED_ANIMATION_DURATION的值设置为所需的任何时间间隔即可。 A smaller time interval will mean faster speed. 时间间隔越短,速度越快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM