IOS中AppDelegate类中的方法触发时机-----自定义AppDelegate的写法
2015-08-27 21:43
411 查看
@implementation AppDelegate //当应用程序加载时触发,创建window窗口对象,让对象的window成为程序的主窗口,并且可视. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. //__FUNCTION__方法名__LINE__所在的行数 NSLog(@"%s,%d",__FUNCTION__,__LINE__); self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } //应用程序将要取消活跃状态是触发' //使用该方法暂停掉正在执行的任务,让定时器失效,暂停游戏. - (void)applicationWillResignActive:(UIApplication *)application { NSLog(@"%s,%d",__FUNCTION__,__LINE__); // 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. } //当应用程序进入后台时触发 //释放共享资源,保存用户数据,让timer失效,保存当前程序退出时会替换applicationWillTerminate - (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"%s,%d",__FUNCTION__,__LINE__); // 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. } //当应用程序将要进入前台时触发 //继续进入后台时正在运行的任务,游戏继续进行 - (void)applicationWillEnterForeground:(UIApplication *)application { NSLog(@"%s,%d",__FUNCTION__,__LINE__); // 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. } //当应用程序成为活跃状态时触发 //重新启动当前应用程序进入活跃状态时暂停的任务,如果之前程序在后台,此时可以选择刷新界面. - (void)applicationDidBecomeActive:(UIApplication *)application { NSLog(@"%s,%d",__FUNCTION__,__LINE__); // 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. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } -(void)dealloc { [_window release]; [super dealloc]; } @end
重写AppDelegate
//LODelegate,注意继承
// UIResponder<UIApplicationDelegate>
@interface LODelegatre : UIResponder<UIApplicationDelegate> @property (retain, nonatomic) UIWindow *window; @end
#import "LODelegatre.h" @implementation LODelegatre - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];; self.window.backgroundColor = [UIColor yellowColor]; [self.window makeKeyAndVisible]; return YES; } - (void)dealloc { [_window release]; [super dealloc]; } @end
相关文章推荐
- Android ImageView
- Android学习心得(15) --- Dex文件结构解析(1)
- Unity常用代码
- iOS中实现心块的颜色轮转(重点:交换颜色,设置定时器)
- Photoshop脚本 > 批量生成各尺寸的iOS图标
- Android Studio (Gradle)编译错误
- 最近设计的一个无人机app的界面
- Android颜色对照表
- 11款手机微信小游戏源码特效
- ios开发进阶之多线程02 NSOperation
- Android 线程详解
- Android 高仿微信6.0主界面 切换图标变色
- Django之第一个app<3>
- iOS中ScrollView(滚屏,引导界面,和判段是否是第一次登陆)
- createElement appendChild
- swift详解之十三 -----------AppDelegate
- iOS-点餐系统
- Cloud Computing Application Notes
- Android不编译某个模块
- Android中Preference的使用以及监听事件分析