在PageViewController中隐藏/显示特定视图控制器的状态栏

时间:2014-10-28 23:38:52

标签: ios objective-c cocoa-touch uipageviewcontroller

我有一个包含3个视图控制器的UIPageViewController。我想隐藏前两个视图控制器的状态栏,并显示最后一个视图控制器的状态栏。最好的方法是什么?

1 个答案:

答案 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];
        }
    }
}