UIWindow

一个特殊的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成为主窗口,但不显示;

你可能感兴趣的:(UIWindow)