我使用一个UIPageViewController与PageControl显示3图像在我的PageViewController。一切都很完美。但是,页面是否可能在特定时间后自动滑动(滚动)到下一页?
使用NSTimer在特定时间后滚动。我希望下面的代码对你有帮助
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(move_pagination) userInfo:nil repeats:YES];
之后定义"move_pagination"方法,如
- (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;
}
}
可以使用下面的方法
- (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion;
为例:[pageVCObj setViewControllers:arrayOfViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];