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

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

相关文档推荐

Cancel current UIScrollView touch(取消当前 UIScrollView 触摸)
Scale image to fit screen on iPhone rotation(缩放图像以适应 iPhone 旋转时的屏幕)
How to make a screenshot of all the content of a Scrollview?(如何截取 Scrollview 的所有内容?)
Swift iOS Set scrollView constraint below navigation bar programmatically(Swift iOS以编程方式在导航栏下方设置滚动视图约束)
UILabel sizeToFit method not working properly(UILabel sizeToFit 方法无法正常工作)
Get the current UIScrollView scroll values on the iPhone?(获取 iPhone 上当前的 UIScrollView 滚动值?)