Add a UIView above all, even the navigation bar

前端 未结 17 1666
悲&欢浪女
悲&欢浪女 2020-11-29 15:36

I want to display, above any other views, even the navigation bar, a kind of \"pop-up\" view that looks like this:

  • full screen black background with a 0.5 alph
17条回答
  •  無奈伤痛
    2020-11-29 16:14

    I recommend you to create a new UIWindow:

    UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    window.rootViewController = viewController;
    window.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    window.opaque = NO;
    window.windowLevel = UIWindowLevelCFShareCircle;
    window.backgroundColor = [UIColor clearColor];
    
    [window makeKeyAndVisible];
    

    Then you can manage your view in an other UIViewController. To remove the windows:

    [window removeFromSuperview];
    window = nil;
    

    hope that will help!

提交回复
热议问题