顯然,一個需要實例化的故事板,如果需要定製UIWindow
呈現窗口爲好。僅僅提供一個UIWindow
實例是不夠的。
首先,刪除密鑰UIMainStoryboardFile
從您的主應用程序的Info.plist
文件。
然後在代碼中應用程序添加到都推出處理程序:
- 實例化窗口和分配給應用程序委託的財產。
- 實例化故事板。
- 實例化初始視圖控制器
- 將視圖控制器分配給窗口。
- 顯示窗口。
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window : UIWindow?
// ...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = MainWindow(frame: UIScreen.main.bounds)
// We need to instantiate our own storyboard instead of specifying one in `Info.plist` since we need our own custom `UIWindow` instance.
// Otherwise if we just create the custom UIWindow instance and let the system creates a storyboard,
// then the application won't respond to the keyboard/remote (user input).
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
window?.rootViewController = storyboard.instantiateInitialViewController()
defer {
window?.makeKeyAndVisible()
}
// ... All other setup code
}
// ...
}