iOS APP与ViewController、ViewContr
APP、APP与ViewController
- 启动app
⬇️ ----- didFinishLaunchingWithOptions
⬇️ ---------- viewDidLoad
⬇️ ---------- viewWillAppear
⬇️ ---------- viewWillLayoutSubviews
⬇️ ---------- viewDidLayoutSubviews
⬇️ ---------- viewDidAppear
⬇️ ----- applicationDidBecomeActive
总结:
1,整体顺序是:app加载
→ 根视图控制器加载
→ app活跃
2,注意:app活跃
是发生在根视图控制器DidAppear
之后的
3,注意:在app的启动过程中是没有将要进入前台(applicationWillEnterForeground)
这个步骤的
- 单击Home键,app进入后台
⬇️ ----- applicationWillResignActive
⬇️ ----- applicationDidEnterBackground
总结:
1,整体顺序是:app将不活跃
→ app进入后台
2,注意:在app进入后台的过程中,ViewController是不参与其中的,也就是说当前屏幕上显示的ViewController并不会调用视图控制器将要消失(viewWillDisappear)
和 视图控制器已经消失(viewDidDisappear)
- 点击APP桌面图标,app进入前台
⬇️ ----- applicationWillEnterForeground
⬇️ ----- applicationDidBecomeActive
总结:
1,整体顺序是:app将要进入前台
→ APP活跃
2,注意:跟app进入后台一样,在该过程中,ViewController是不参与其中的,在屏幕上出现的ViewController并不会调用视图控制器将要显示(viewWillAppear)
和 视图控制器已经显示(viewDidAppear)
- app锁屏
⬇️ ----- applicationWillResignActive
⬇️ ----- applicationDidEnterBackground
总结:
1,app锁屏操作所产生的生命周期跟app进入后台是相同的
- app解锁
⬇️ ----- applicationWillEnterForeground
⬇️ ----- applicationDidBecomeActive
总结:
1,app解锁操作所产生的生命周期跟app进入前台是相同的
- app销毁
⬇️ ----- applicationWillResignActive
⬇️ ----- applicationDidEnterBackground
⬇️ ----- applicationWillTerminate
总结:
1,整体顺序是:app将不活跃
→ app进入后台
→ app将要销毁
2,注意:这个过程ViewController同样是不参与的
- 双击Home键,由app进入app卡片列表
⬇️ ----- applicationWillResignActive
总结:
1,在app进入app卡片列表的过程中,仅有一步被调用:app将不活跃(applicationWillResignActive)
2,注意:如果此时,用户在app卡片列表中选择了其他app,接下来会调用:app进入后台(applicationDidEnterBackground)
3,注意:如果此时,用户点击Home键,app由app卡片列表重新回到前台,接下来会调用:app活跃(applicationDidBecomeActive)
,要注意的是在这个过程中并不会调用app将要进入前台(applicationWillEnterForeground)
ViewController与ViewController
- vc1 PushTo / PresentTo vc2
⬇️ -----vc2----- viewDidLoad
⬇️ -----vc1----- viewWillDisappear
⬇️ -----vc2----- viewWillAppear
⬇️ -----vc2----- viewWillLayoutSubviews
⬇️ -----vc2----- viewDidLayoutSubviews
⬇️ -----vc2----- viewDidAppear
⬇️ -----vc1----- viewDidDisappear
⬇️ -----vc1----- presentViewCompleted (optional)
//[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"-----vc2-----dismissViewControllerCompleted");
}];
- vc2 PopTo / DismissTo vc1
⬇️ -----vc2----- viewWillDisappear
⬇️ -----vc1----- viewWillAppear
⬇️ -----vc1----- viewDidAppear
⬇️ -----vc2----- viewDidDisappear
⬇️ -----vc2----- dismissViewControllerCompleted (optional)
//[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"-----vc2-----dismissViewControllerCompleted");
}];
⬇️ -----vc2----- dealloc
Demo地址:https://github.com/MajorLMJ/LMJTest_APPLifeCycle
版权声明:出自MajorLMJ技术博客的原创作品 ,转载时必须注明出处及相应链接!