UIWindow 覆盖不可见

UIWindow overlay not visible

尝试向 IOS 应用中的关键 UIWindow 添加叠加层 window。 但是,新的覆盖 UIWindow 似乎在任何地方都看不到。

不过,根据 lldb:

,似乎添加成功了
(lldb) po UIApplication.shared.windows
▿ 2 elements
  - 0 : <UIWindow: 0x7fdfd3d0aec0; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x60800004d680>; layer = <UIWindowLayer: 0x608000220980>>
  - 1 : <UIWindow: 0x7fdfd3c0d010; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x60000004c9c0>; layer = <UIWindowLayer: 0x6000002216e0>>

在调试中,

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let vc = UIViewController()
    vc.view.backgroundColor = UIColor.blue

    let window = UIWindow()
    window.frame = self.view.bounds
    window.backgroundColor = UIColor.blue
    window.windowLevel = UIWindowLevelStatusBar
    window.rootViewController = vc
    window.isHidden = false
}

将不胜感激 hint/help 谢谢

您的 window 在您的 viewDidLoad() 方法退出后被释放。您需要强烈保留您的第二个 window.