4

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

4

2 回答 2

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];
于 2013-03-25T09:44:05.160 回答
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;
}

}

于 2013-03-25T09:55:56.783 回答