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

How do i make a UIScrollView scroll automatically at a certain speed?(如何使 UIScrollView 以一定的速度自动滚动?)
本文介绍了如何使 UIScrollView 以一定的速度自动滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 以一定的速度自动滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
NSURLSessionTaskPriority seems to be ignored?(NSURLSessionTaskPriority似乎被忽略了?)
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?(如何用EPSInside Rect将dataWithEPSInside Rect变成矢量而不是位图的矢量格式?)