Reputation: 4594
I have a horizontal scrollView
which contains 2 images.The scrollView
is circular.What I want to do is to set automatic scroll after a few seconds.Any idea how could I do that?
I tried the following:
[UIScrollView beginAnimations:@"scrollAnimation" context:nil];
[UIScrollView setAnimationDuration:5];
[UIScrollView setContentOffset:CGPointMake(self.view.frame.size.width, 0)];
[UIScrollView commitAnimations];
but this: [UIScrollView setContentOffset:CGPointMake(self.view.frame.size.width, 0)];
is not recognized.Any idea?Thanks
Upvotes: 1
Views: 1304
Reputation: 15639
Do Something like this :-)
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
- (void) onTimer {
// Updates the variable h, adding 100 (put your own value here!)
h += 100;
//This makes the scrollView scroll to the desired position
yourScrollView.contentOffset = CGPointMake(0, h);
}
Upvotes: 1
Reputation: 6413
you've misunderstood the animation declaration syntax let's suggest, you have your scroll view referenced as following in your code:
UIScrollView *scrollView = ...; // it must have a reference to the actual scroll view instance
...
[UIView beginAnimations: @"scrollAnimation" context:nil];
[UIView setAnimationDuration: 5.0f];
[scrollView setContentOffset:CGPointMake(x,y)];
[UIView commitAnimations];
this should work for you
Upvotes: 1