To create a new UIWindow over the main window

后端 未结 8 2381

In my app I want to create a new UIWindow over the main UIWindow, And I wrote as following, but it don\'t works. first, i create a UIWindow as the

相关标签:
8条回答
  • 2020-12-07 23:24

    Your window1 object is a local variable, when the code runs out of this method, this object does not exist any more. Any UIWindow object we created will be add to the [[UIApplication sharedApplication] windows], but this array only keep a week reference to any UIWindow object, so it's up to your own code to keep the window object exist.Why apple achieved like this, I guess, is [UIApplication sharedApplication] object exists as long as the app runs, doing so to avoid keeping the UIWindow objects which only need to be exist for a while living in the memory "forever".

    What's more, your code could run with MRC.

    0 讨论(0)
  • 2020-12-07 23:25

    if you just need to change shared window ViewController in swift 5

    UIApplication.shared.keyWindow?.rootViewController = UINavigationController(rootViewController: yourViewController)
    
    0 讨论(0)
提交回复
热议问题