一個特殊的UIView,現在一個app中會有1-3個UIWindow;如:狀態欄的提醒自定義控件...
沒有UIWindow也就不會看到任何UI界面,先創建UIWindow,再創建控制器,創建控制器的view,然后將控制器的view添加到UIWindow上;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// 創建窗口
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// 窗口背景色
_window.backgroundColor = [UIColor whiteColor];
// 實例控制器 a
AViewController *a = [[AViewController alloc] init];
BViewController *b = [[BViewController alloc] init];
// 實例導航控制器 anav
UINavigationController *anav = [[UINavigationController alloc] initWithRootViewController:a];
UINavigationController *bnav = [[UINavigationController alloc] initWithRootViewController:b];
// 實例tab
UITabBarController *tab = [[UITabBarController alloc] init];
// nav加到tab上
tab.viewControllers = @[anav, bnav];
// 設置根控制器為nav
self.window.rootViewController = tab;
// 設置為主窗口并顯示出來
[_window makeKeyAndVisible];
return YES;
}
[_window makeKeyWindow]; //讓UIWindow成為主窗口,但不顯示;