zoukankan      html  css  js  c++  java
  • 隐藏状态栏statusbar

    在iOS7以后,隐藏状态栏只需要在根controller中添加

    -(BOOL)prefersStatusBarHidden{
        return YES;
    }

    即可。但在有UINavigationController和UITabbarController时,在设置rootViewController后

    //MainViewController为UITabbarController型
    MainViewController *mainVC = [[MainViewController alloc]init];
    UINavigationController *naviVC = [[UINavigationController alloc]initWithRootViewController:mainVC];
    self.window.rootViewController = naviVC;

    在MainViewController中想隐藏状态栏,但在该controller设置时无效。

    在网上查了很多资料,甚至给UINavigtionController增加category,并在所需controller中引入category后仍不起作用。如下:

    //.h文件
    @interface UINavigationController (StatusBar)
    
    -(BOOL)prefersStatusBarHidden;
    
    @end
    
    //.m文件
    @implementation UINavigationController (StatusBar)
    
    -(BOOL)prefersStatusBarHidden{
        return [[self topViewController] prefersStatusBarHidden];
    }
    
    @end

    最后恍然大悟,必须在rootController中设置prefersStatusBarHidden为YES才可以。
    在UITabbarController中,还需添加子controller

    [self addChildViewController:childController];

    所以就需要在这些子controller中设置prefersStatusBarHidden为YES才有效。绕了一大圈……

  • 相关阅读:
    hdu3829(最大独立集)
    hdu2444(判二分图+最大匹配)
    hdu2063+hdu1083(最大匹配数)
    hdu3622(二分+two-sat)
    poj3678(two-sat)
    hdu1824(two-sat)
    hdu3062(two-sat)
    POJ1067 取石子游戏
    POJ1066 Treasure Hunt
    POJ1065 Wooden Sticks
  • 原文地址:https://www.cnblogs.com/Apologize/p/4895521.html
Copyright © 2011-2022 走看看