how can I make a scrollView autoscroll?

Mihai picture Mihai · Mar 13, 2013 · Viewed 11.4k times · Source

I have this scrollView:

self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.scrollView.contentSize = CGSizeMake(320,3000);


_scrollView.frame = CGRectMake(0, 45, 320, 420);

and I want to make it autoscroll very slowly downward to the end so that the user can see the content (as in movie credits), eventually with a button to stop/play, but to follow the user gestures when touching the interface.

How can I do this? Thanks,

Answer

Apollo SOFTWARE picture Apollo SOFTWARE · Mar 13, 2013

You can use:

  [_scrollView setContentOffset:CGPointMake(x,y) animated:YES];

and use the x and y as the touch points on the screen you can capture.

You can also do an animation with CoreAnimation:

 [UIScrollView beginAnimations:@"scrollAnimation" context:nil];
 [UIScrollView setAnimationDuration:1.0f];
 [scroll setContentOffset:CGPointMake(x, y)];
 [UIScrollView commitAnimations];