您的位置:首页 > 移动开发

app 生命周期

2016-01-05 00:00 92 查看
@implementation AppDelegate
// Home 按键 : shitf+command +h
// application
// 应用程序加载完会跑这个方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// UIWindow : 窗口类;
// 在加载应用程序完成后,创建windows 对象
// 一个应用程序至少要有一个窗口对象;(95% 的应用程序都只有一个窗口对象)
// CGRect frme = CGRectMake(0, 0, 33, 33);
// 创建一个窗口对象,并把尺寸设置屏幕大小
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
// UIscreen 是个单例,使用类方法获取屏幕对象,可以通过该屏幕获取当前对象屏幕大小;
// struct CGRect {
// CGPoint origin;
// CGSize size;
// };

// struct CGPoint {
// CGFloat x;
// CGFloat y;
// };
// struct CGSize {
// CGFloat width;
// CGFloat height;
// };
CGRect rect = [UIScreen mainScreen].bounds;
//[UIScreen mainScreen];
// 设置背景颜色;
self.window.backgroundColor = [UIColor redColor];
// 让窗口的并显示出来;
self.window.rootViewController = [[UIViewController alloc]init];

[self.window makeKeyAndVisible];

NSLog(@"%@",NSStringFromCGRect(rect));

NSLog(@"download over..");
// 程序入口;
return YES;
}
// 应用程序将要进入后台时候调用
- (void)applicationWillResignActive:(UIApplication *)application {
// 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.
// 这个方法里面可以释放共有的资源,保存数据,停止计时器等等操作;

NSLog(@"即将进入后台调用....");
}

// 应用程序进入后台时调用
- (void)applicationDidEnterBackground:(UIApplication *)application {
// 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.
NSLog(@"已经进入后台");

}

- (void)applicationWillEnterForeground:(UIApplication *)application {
// 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.
NSLog(@"应用程序将要进入前台....");
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// 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.
// 重新启动应用程序
NSLog(@"应用程序已经进入前台");
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
NSLog(@"应用程序终止...");
}
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
// 释放内存的操作;
NSLog(@"内存不足就调用该方法");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  app 生命周期