// 1.創(chuàng)建窗口,注意窗口必須要有尺寸,尺寸跟屏幕一樣大的尺寸,窗口不要被釋放
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor redColor];
// 2.創(chuàng)建窗口的跟控制器
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor yellowColor];
[vc.view addSubview:[UIButton buttonWithType:UIButtonTypeContactAdd]];
// 如果設(shè)置窗口的跟控制器艺普,默認(rèn)就會(huì)把控制器的view添加到窗口上
// 設(shè)置窗口的跟控制器损离,默認(rèn)就有旋轉(zhuǎn)功能
self.window.rootViewController = vc;
// [self.window addSubview:vc.view];
// 3.顯示窗口
[self.window makeKeyAndVisible];
```
window是有層級(jí)的,而且不是只有一個(gè)
AppDelegate
```objc
// 程序啟動(dòng)完成的時(shí)候調(diào)用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSLog(@"%s",__func__);
return YES;
}
// 當(dāng)app失去焦點(diǎn)的時(shí)候調(diào)用
- (void)applicationWillResignActive:(UIApplication *)application {
NSLog(@"%s",__func__);
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
// app進(jìn)入后臺(tái)的時(shí)候調(diào)用
// app忽然打斷的時(shí)候疆瑰,在這里保存一些需要用到的數(shù)據(jù)
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"%s",__func__);
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
// app進(jìn)入即將前臺(tái)
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSLog(@"%s",__func__);
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
// 當(dāng)app獲取到焦點(diǎn)的時(shí)候調(diào)用葛峻,意味著app可以與用戶(hù)交互
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(@"%s",__func__);
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
// app被關(guān)閉的時(shí)候調(diào)用
- (void)applicationWillTerminate:(UIApplication *)application {
NSLog(@"%s",__func__);
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
// app接收到內(nèi)存警告的時(shí)候調(diào)用
// 清空?qǐng)D片的緩存
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
NSLog(@"%s",__func__);
}