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.
Asked
Active
Viewed 6,328 times
1 Answers
20
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.

HG's
- 818
- 6
- 22
-
I know a similar method of animation had stopped being used in 3.0 and was replaced with [UIView animation..]. Does this count as the original type, or is this still a recommended method? – Andrew May 22 '11 at 13:05
-
This is the same original method. UIScrollView inherits from UIView so the same animation methods can be put for it. You can replace UIScrollView with UIView in the code posted. The result will be the same. – HG's May 22 '11 at 14:09