I'm using an UIPageViewController with a PageControl to display 3 images in my PageViewController. All works perfect. But is it possible that the Pages are swiping (scrolling) to the next page after a specific time automatically?
Asked
Active
Viewed 4,580 times
4
-
2use NSTimer for achieve this one. – Balu Mar 25 '13 at 09:44
2 Answers
0
this is possible with this below method
- (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion;
For Ex:
[pageVCObj setViewControllers:arrayOfViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];

BhushanVU
- 3,455
- 1
- 24
- 33
-
This moves to the next page but not in an animated manner. Is there some method to scroll automatically with animation? – Tushar Koul Mar 31 '14 at 09:07
-
Incorrect answer, guy asked about automatically. this code will not work automatic. – karan Feb 20 '15 at 07:08
0
Use NSTimer to scroll after particular time.I hope following code will help you
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(move_pagination) userInfo:nil repeats:YES];
after that define "move_pagination" method like
- (void)scrollingTimer {
UIScrollView *scrMain = (UIScrollView*) [self.view viewWithTag:1];
UIPageControl *pgCtr = (UIPageControl*) [self.view viewWithTag:12];
CGFloat contentOffset = scrMain.contentOffset.x;
// calculate next page to display
int nextPage = (int)(contentOffset/scrMain.frame.size.width) + 1 ;
// if page is not 10, display it
if( nextPage!=10 ) {
[scrMain scrollRectToVisible:CGRectMake(nextPage*scrMain.frame.size.width, 0, scrMain.frame.size.width, scrMain.frame.size.height) animated:YES];
pgCtr.currentPage=nextPage;
// else start sliding form 1 :)
} else {
[scrMain scrollRectToVisible:CGRectMake(0, 0, scrMain.frame.size.width, scrMain.frame.size.height) animated:YES];
pgCtr.currentPage=0;
}
}

Madhumitha
- 3,794
- 8
- 30
- 45