問(wèn)題描述
我正在使用 touchesBegan 和 touchesMoved 來(lái)跟蹤用戶的交互,因此我可以看到用戶觸摸屏幕的位置.我想要做的是當(dāng)他們將手指移到屏幕的最后 20 個(gè)像素時(shí),讓 UIScrollView scroll1 向下滾動(dòng).但是我如何定義速度?當(dāng)然,while 語(yǔ)句會(huì)執(zhí)行得太快,而 UIView 動(dòng)畫(huà)會(huì)將其移動(dòng)到某個(gè)位置,但只會(huì)移動(dòng)一次.
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.
推薦答案
您可以通過(guò)以下代碼做到這一點(diǎn):
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 的值設(shè)置為您想要的任何時(shí)間間隔.更小的時(shí)間間隔將意味著更快的速度.
Just set the values of REQUIRED_ANIMATION_DURATION to whatever time interval you want. A smaller time interval will mean faster speed.
這篇關(guān)于如何使 UIScrollView 以一定的速度自動(dòng)滾動(dòng)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!