
[英]Is it possible to scroll automatically in UIPageViewController iOS
[英]UIPageViewController scroll automatically issue
我使用这样的计时器每隔5秒就实现了UIPageViewController
自动滚动:
_bannerTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(loadNextController)
userInfo:nil
repeats:YES];
- (void)loadNextController
{
self.index++;
HeaderAdVC *nextViewController;
if(self.index>arrayImages.count-1)
{
self.index=0;
[pageIndicator setCurrentPage:0];
nextViewController = [self viewControllerAtIndex:0];
}
else
{
nextViewController = [self viewControllerAtIndex:self.index];
}
[pageIndicator setCurrentPage:self.index];
[pageController setViewControllers:@[nextViewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
并在viewWillDisappear
删除计时器
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[_bannerTimer invalidate];
}
问题:
我的问题是当调用loadNextController
方法我的应用程序停止响应。 如果我切换到下一页仍然在每个视图上遇到相同的问题。
做下面的一些更改,在后台线程中执行所有non-ui
任务,在主线程中执行所有UI
操作,试试这个
- (void)loadNextController
{
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
self.index++;
HeaderAdVC *nextViewController;
if(self.index>arrayImages.count-1)
{
self.index=0;
[pageIndicator setCurrentPage:0];
nextViewController = [self viewControllerAtIndex:0];
}
else
{
nextViewController = [self viewControllerAtIndex:self.index];
}
dispatch_async(dispatch_get_main_queue(), ^{
[pageIndicator setCurrentPage:self.index];
[pageController setViewControllers:@[nextViewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
});
});
}
我希望这能帮到您 ..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.