2017-06-20 43 views
2

而觸摸事件被傳遞到他們發生沒有相關的座標值傳送到 的關鍵窗口, 事件窗口。一次只能有一個窗口成爲關鍵窗口,並且您可以使用窗口的isKeyWindow屬性來確定其狀態。 大多數情況下,您的應用的主窗口是關鍵窗口,但UIKit 可能會根據需要指定不同的窗口。 https://developer.apple.com/documentation/uikit/uiwindow爲什麼我們需要設置keywindow iOS中

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 
} 

,我讀了,但仍然不明白爲什麼我們需要一個窗口設置爲重要窗口。

而觸摸事件被傳遞到它們發生時的窗口, 事件沒有相關的座標值的關鍵窗口

交付給 什麼讓一個窗口的作用關鍵,它不會發生什麼?

由於

回答

1
  • makeKeyAndVisible消息使一個窗口鍵,並且移動它是 在其水平的任何其他窗口的前面。

  • makeKeyAndVisible的呼叫用於指定哪一個是最新的。

  • 它將新視圖控制器分配給窗口的rootViewController屬性,然後使窗口在屏幕上可見。

    - 這是一種方便的方法,用於顯示當前窗口並將其定位在同一級別或更低級別的所有其他窗口之前。如果您只想顯示窗口,請將其 隱藏的 屬性更改爲 否see Apple Doc

相關問題