我有一个包含3个视图控制器的UIPageViewController
。我想隐藏前两个视图控制器的状态栏,并显示最后一个视图控制器的状态栏。最好的方法是什么?
答案 0 :(得分:2)
在PageViewController的委托中,添加此内容。
- (BOOL)prefersStatusBarHidden
{
PageContentViewController *controller = self.pageViewController.viewControllers[0];
if (controller.pageIndex == 2) {
return NO;
} else {
return YES;
}
}
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
if (completed) {
PageContentViewController *controller = self.pageViewController.viewControllers[0];
NSUInteger pageIndex = controller.pageIndex;
// only update status bar when transition is between page 2 and page 3
if (pageIndex == 1 || pageIndex == 2) {
[self setNeedsStatusBarAppearanceUpdate];
}
}
}