To create a new UIWindow over the main window

后端 未结 8 2357

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:02

    Swift 4

    To avoid memory leak, I prefer to initialise my custom window in this way, as proposed by Apple :

    If you want to provide a custom window for your app, you must implement the getter method of this property and use it to create and return your custom window.

    Example:

    var myCustomWindow: UIWindow? = CustomWindow(frame: UIScreen.main.bounds)
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
        let mainController: MainViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as! MainViewController
        self.myCustomWindow?.rootViewController = mainController
        self.myCustomWindow?.makeKeyAndVisible()
    }
    

提交回复
热议问题