How do i make a UIScrollView scroll automatically

2019-02-07 04:32发布

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.

1条回答
\"骚年 ilove
2楼-- · 2019-02-07 05: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.

查看更多
登录 后发表回答