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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)