I have this code for a scrollView (with paging enabled)
-开发者_如何学运维 (IBAction) random{
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * (arc4random() % (numberOfPage - 1));
frame.origin.y = 0;
[scrollView scrollRectToVisible:frame animated:YES];}
It make a random paging scroll and it's ok, but it is very slow. Can I have a fast scrolling as a slot machine?
I'm not sure you could get it to look like slot machine (you'd probably need some motion blur to get that kind of effect), but you could try putting your scrollRectToVisible:
in an animation block to change the duration of the animation:
- (IBAction) random
{
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * (arc4random() % (numberOfPage - 1));
frame.origin.y = 0;
[UIView animateWithDuration: <your duration>
animations:^(void) {
[scrollView scrollRectToVisible:frame animated: NO];
}];
}
Don't forget the animated:NO
, otherwise it'll override your duration
精彩评论