【问题标题】:status bar overlaps with navigation bar状态栏与导航栏重叠
【发布时间】:2023-04-09 09:58:02
【问题描述】:

我在我的应用程序中通过代码添加导航控制器。其他一切正常,但我的导航栏与状态栏重叠。我尝试添加

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone; 

但它不起作用。

我在该导航控制器中的其他控制器仅在 xibs 中,而不是在情节提要中。 请帮忙。

【问题讨论】:

    标签: iphone uinavigationcontroller ios7 autolayout statusbar


    【解决方案1】:

    如果您真的不希望您的导航栏是半透明的,请使用此代码,您的问题将得到解决:

    self.navigationController.navigationBar.translucent = NO;
    

    【讨论】:

      【解决方案2】:

      我用下面的代码解决了这个问题(suggested by Tacettin Özbölük):

      if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
          UIView *addStatusBar = [[UIView alloc] init];
          addStatusBar.frame = CGRectMake(0, 0, 320, 20);
          addStatusBar.backgroundColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1]; //change this to match your navigation bar
          [self.window.rootViewController.view addSubview:addStatusBar];
      }
      

      【讨论】: