那麼,其實3,但一個是UITextEffectsWindow
。爲什麼我的應用程序中有兩個UIWindows,爲什麼第一個隱藏?
於是,我開始了一個簡單的測試應用程序。
的AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ViewController *controller = [[ViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
}
在的viewController我標註的觀點:
self.view.tag = 999;
當我退出這個
NSLog(@"[UIApplication sharedApplication].windows = %@",[UIApplication sharedApplication].windows);
for (UIWindow* window in [UIApplication sharedApplication].windows) {
NSLog(@"tag = %d",window.rootViewController.view.tag);
}
我得到這個:
2015-04-04 08:59:44.440 SDK[45888:1495552] [UIApplication sharedApplication].windows = (
"<UIWindow: 0x7fc57371e1e0; frame = (0 0; 375 667); hidden = YES; gestureRecognizers = <NSArray: 0x7fc57371eb10>; layer = <UIWindowLayer: 0x7fc57371c2f0>>",
"<UIWindow: 0x7fc57352b0d0; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x7fc5750115f0>; layer = <UIWindowLayer: 0x7fc573526f20>>",
"<UITextEffectsWindow: 0x7fc5750260c0; frame = (0 0; 375 667); opaque = NO; gestureRecognizers = <NSArray: 0x7fc575026fb0>; layer = <UIWindowLayer: 0x7fc575026580>>"
)
2015-04-04 09:03:33.319 SDK[46643:1499077] tag = 999
2015-04-04 09:03:33.319 SDK[46643:1499077] tag = 0
2015-04-04 09:08:11.648 SDKVevo[47379:1501367] key
2015-04-04 09:03:33.319 SDK[46643:1499077] tag = 0
正如你所看到的,有兩個UIWindows,第一個是隱藏的。此外,第一個標籤是999,所以這是VC實例化並設置爲根。但是,那個窗戶怎麼被標記爲隱藏?爲什麼有兩個呢?爲什麼第二個窗口會作爲keyWindow註銷?
當我運行應用程序,我居然看到了VC我實例化,並標記爲999,但日誌說這是不keyWindow,這也是一個隱藏的窗口的一部分。
你是從一個故事板標準的單一視圖的應用程序啓動?如果是這樣,故事板將爲您創建一個窗口,並創建另一個窗口。 – rdelmar 2015-04-04 16:14:38