How do i make a UIScrollView scroll automatically at a certain speed?
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? Sure开发者_开发技巧ly 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];
Just set the values of REQUIRED_ANIMATION_DURATION to whatever time interval you want. A smaller time interval will mean faster speed.
精彩评论