在TabbarViewController中隐藏特定视图控制器中的状态栏

时间:2015-02-09 11:50:54

标签: ios objective-c statusbar tabbar

我有TabbarViewController。在一个选项卡中,当导航到特定ViewController(详细信息图像视图)时,我想隐藏状态栏。 我看过这个链接: How to hide a status bar in iOS?

但在我的情况下,它不起作用,因为我不想在整个应用程序中隐藏状态栏,而只是在特定的ViewController中。

有没有办法只在某个标签中实现隐藏滚动条?

*编辑: 我想隐藏状态栏的ViewController是一个PageViewController。这是问题吗?

2 个答案:

答案 0 :(得分:2)

    -(void) viewDidAppear:(BOOL)animated{
        [super viewDidAppear:YES];
        if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight){
        if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){
            [self prefersStatusBarHidden];
            [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
        }
        else{
            // iOS 6
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
        }

    }
    else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown){
        if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
            [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
        }
        else{
            // iOS 6
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
        }
    }
}

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden {
    return YES;
}

答案 1 :(得分:0)

请尝试以下代码:

- (void) viewWillAppear:(BOOL)animated{
    [UIApplication sharedApplication].statusBarHidden = YES;
}