iOS:状态栏和导航栏:空格或底层

时间:2013-08-05 13:26:58

标签: ios uinavigationbar uistatusbar

如何以规范方式使用状态栏和导航进行操作?

所以,我的目标是同时隐藏和显示状态栏和导航栏。

我应该以规范的方式做什么,避免它们之间的空间,避免底层(状态栏位于导航栏上)并支持正常旋转?

我玩过它,现在我有代码:

-(void)tryToManipulateWithTopBarsIsHidden:(BOOL)hidden{
    if (self.wantsFullScreenLayout) {

        // Get status bar height if visible

        CGFloat statusBarHeight = 0;
        [self topBarsHiddenStateAppearingOrDisappearingStatusBarHidden:hidden
                                                   navigationBarHidden:hidden];
        // Get status bar height if visible
        if (![UIApplication sharedApplication].statusBarHidden) {
            CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
            statusBarHeight = MIN(statusBarFrame.size.height, statusBarFrame.size.width);
//            statusBarOrigin = MIN(statusBarFrame.origin.x,statusBarFrame.origin.y);
        }

        // Set navigation bar frame
        // if status bar is visible and
        // nav bar origin in y is not the same as status bar (magic, really)
        // we need to set nav bar origin y to status bar origin y (auto shifting to bottom)
        CGRect navBarFrame = self.navigationController.navigationBar.frame;
        // if status bar is visible
        if (![UIApplication sharedApplication].statusBarHidden){
            navBarFrame.origin.y = statusBarHeight;
            navBarFrame = CGRectOffset(navBarFrame, 0.0, -20.0);
            self.navigationController.navigationBar.frame = navBarFrame;
        }
        self.navigationController.navigationBar.hidden =[UIApplication sharedApplication].statusBarHidden ;
        LogRect(@"this is statusBar ", [UIApplication sharedApplication].statusBarFrame);
        LogRect(@"this is navigationBar ", navBarFrame);
    }
}

- (void)setTopBarStatusBarHidden:(BOOL)hidden onCompletion:(void(^)(UINavigationBar*))completion andNavigationBar:(UINavigationBar*)bar{
    [[UIApplication sharedApplication] setStatusBarHidden:hidden];
    completion(bar);
}

- (void)setTopBarNavBarHidden:(BOOL)hidden{
    [self.navigationController setNavigationBarHidden:hidden animated:NO];
}

- (void)topBarsHiddenStateAppearingOrDisappearingStatusBarHidden:(BOOL)statusBarHidden
                                             navigationBarHidden:(BOOL)navigationBarHidden{

    UINavigationBar* bar = self.navigationController.navigationBar;
    id fles = self;
    [self setTopBarStatusBarHidden:statusBarHidden
                      onCompletion:^(UINavigationBar *bar) {
                          if (statusBarHidden){
                              [fles setTopBarNavBarHidden:navigationBarHidden];
                          }
                          else
                              [fles setTopBarNavBarHidden:navigationBarHidden];

                      }
                  andNavigationBar:bar];
}

但没有!

任何人都可以解释如何在没有这个混乱的情况下解决这个问题(真的不能正常工作的代码)吗?

1 个答案:

答案 0 :(得分:0)

你只需写下方法:

self.navigationController.navigationBar.hidden = YES;
[UIApplication sharedApplication].statusBarHidden = YES;

这将同时隐藏导航栏和状态栏。