iOS开发 ----- UI生命周期

来源:互联网 发布:淘宝评价截图怎么弄 编辑:程序博客网 时间:2024/06/10 13:04

APP生命周期

main函数

参数说明1. argc  main函数的argc2. argv  main函数的argv3. 传入一个类名,但这个类必须是UIApplication的子类 而这个函数会自动创建UIApplication子类的对象,如果是nil的话,则只创建UIApplication的对象4. 传入代理类的名字main函数开始后,维护了一个消息循环,可以说是一个死循环,知道应用手动退出或者由于内存不足而退出当程序界面发生改变后,会接到相关通知去处理相应的时间#import <UIKit/UIKit.h>#import "AppDelegate.h"int main(int argc, char * argv[]) {    @autoreleasepool {        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));    }}

程序运行过程

1.程序已经准备完成即将进入到界面上进行展示

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

2.此函数在app即将进入后台时调用,也就是双击home键时调用

- (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.}

3.此函数在app进入后台时调用,也就是切换了别的应用,或者被来电中断,则会调用

- (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.}

4.此函数在app即将进入前台时调用,这里可以放一些恢复界面的代码,

- (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.}

5.此函数在app进入前台后调用,已经可以和用户交互了

- (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.}

6.此函数会在app结束时调用

- (void)applicationWillTerminate:(UIApplication *)application {    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}

以上基本上就是app运行的基本流程

0 0