问题描述
我正在使用 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.