NavigationBar 和 StatusBar 上方的 UIView

UIView above NavigationBar and StatusBar

我需要在 NavigationBar 和 StatusBar 上方以全屏模式显示 UIView 我该怎么做?


P.S。对不起我的英语

下面的代码将帮助您。您可以将颜色更改为所需的颜色以获得所需的效果。

UIWindow *window = [[[UIApplication sharedApplication] delegate] window];

UIView *blue = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[blue setBackgroundColor:[UIColor blueColor]];
[window addSubview: blueView];

Swift代码:

if let applicationDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate? {
   if let window:UIWindow = applicationDelegate.window {
      let blueView:UIView = UIView(frame: UIScreen.main.bounds)
      blueView.backgroundColor = UIColor.blue.withAlphaComponent(0.75)
      window.addSubview(blueView)
   }
}

你可能想看看这个人的回答。

How to make a UIView that can cover the navigation bar?

基本上,不要将第二个视图设置为主视图的子视图,而是将第二个视图设置为导航控制器的子视图。