UIPageViewController自动滚动

时间:2013-03-25 09:38:17

标签: xcode ios6 pagecontrol

我正在使用带有PageControl的UIPageViewController在我的PageViewController中显示3个图像。一切都很完美。但页面是否有可能在特定时间后自动滑动(滚动)到下一页?

2 个答案:

答案 0 :(得分:0)

这可以通过以下方法

来实现
- (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion;

对于Ex:

[pageVCObj setViewControllers:arrayOfViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];

答案 1 :(得分:0)

使用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;
}

}