Whereas touch events are delivered to the window where they occurred, events that do not have a relevant coordinate value are delivered to the key window. Only one window at a time can be the key window, and you can use a window’s isKeyWindow property to determine its status. Most of the time, your app’s main window is the key window, but UIKit may designate a different window as needed. https://developer.apple.com/documentation/uikit/uiwindow
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Initialize the window
window = UIWindow.init(frame: UIScreen.mainScreen().bounds)
// Set Background Color of window
window?.backgroundColor = UIColor.whiteColor()
// Allocate memory for an instance of the 'MainViewController' class
let mainViewController = MainViewController()
// Set the root view controller of the app's window
window!.rootViewController = mainViewController
// Make the window visible
window!.makeKeyAndVisible()
return true
}
我读了但还是不明白为什么我们需要将窗口设置为键窗口。
Whereas touch events are delivered to the window where they occurred, events that do not have a relevant coordinate value are delivered to the key window
将窗口设置为键有什么作用,不是之后会发生什么?
谢谢
最佳答案
makeKeyAndVisible
消息生成一个窗口键,并将其移动到 在其级别的任何其他窗口前。调用
makeKeyAndVisible
用于指定哪个是当前的。它将新的 View Controller 分配给窗口的 rootViewController 属性,然后使窗口在屏幕上可见。
- 这是一种显示当前窗口并将其放置在同一级别或更低级别的所有其他窗口前面的便捷方法。如果你只想显示窗口,改变它 隐 属性(property)给 没有 . see Apple Doc
关于ios - 为什么我们需要在iOS中设置keywindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44643787/