xcode - UIPageViewController 自动滚动

标签 xcode ios6 pagecontrol

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

最佳答案

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

}

关于xcode - UIPageViewController 自动滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15611671/

相关文章:

ios - 在属性字符串上设置 NSForegroundColorAttributeName 会在 iOS 6 上向下移动文本

swift - 不同 Controller 的页面控制或 ScrollView

iphone - 在 Iphone 中使用页面控件滑动图像(第 2 部分)

ios5 - webView loadHTMLString 完成?

objective-c - 自迁移以来导航栏和表格 View 之间的黑条

ios - 尽管在 App Store Connect 中仅选择了英语,但我的 iOS 应用程序仍显示多种语言

ios - 无效更新 : invalid number of rows in section 0 terminating with uncaught exception of type NSException

ios - iPhone 6 和 iPhone 6 Plus 上页面 View Controller 的奇怪行为

Xcode 4 : Auto-complete & Jump to Definition broken in my Xcode 3 Project

ios - 与 iPad 上的通知栏重叠