iOS生命周期
介绍
iOS的生命周期代表的是创建、开始、显示、隐藏、停止、销毁。
详细
1 AppDelegate(应用程序生命周期)
在应用程序加载完毕之后调用
[self continue];:之后动作
1.2 应用程序启动
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self continue];
return YES;
}
1.3 即将从前台进入后台
- (void)applicationWillResignActive:(UIApplication *)application{
[self continue];
}
1.4 已经从前台进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application{
[self continue];
}
1.5 应用程序启动
- (void)applicationDidBecomeActive:(UIApplication *)application{
[self continue];
}
1.6 应用程序被杀死或关闭
- (void)applicationWillTerminate:(UIApplication *)application{
[self continue];
}
2 UIViewController(控制器生命周期)
2.1 init初始化
- (instancetype)init{
if (self = [super init]) {
[self continue];
}
return self;
}
2.2 Nib加载成功
//当时xib加载时
- (void)awakeFromNib{
[super awakeFromNib];
[self continue];
}
2.3 加载view
- (void)loadView{
[super loadView];
[self continue];
}
2.4 载入完成,可以进行自定义数据以及动态创建其他控件
- (void)viewDidLoad {
[super viewDidLoad];
[self continue];
}
2.5 视图将出现在屏幕之前
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self continue];
}
2.6 将要对子视图进行调整
- (void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
[self continue];
}
2.7 对子视图进行调整完毕
- (void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
[self continue];
}
2.8
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self continue];
}
2.9 视图将被从屏幕上移除
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self continue];
}
2.10 视图已经被从屏幕上移除
- (void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[self continue];
}
2.11 视图被销毁,此处需要对你在init和viewDidLoad中创建的对象进行释放
- (void)dealloc{
[self continue];
}
2.12 内存警告
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
[self continue];
}
3 UIView(view生命周期)
3.1 当视图添加子视图时调用
- (void)didAddSubview:(UIView *)subview{
[super didAddSubview:subview];
[self continue];
}
3.2 当子视图从本视图移除时调用
- (void)willRemoveSubview:(UIView *)subview{
[super willRemoveSubview:subview];
[self continue];
}
3.3 当视图即将加入父视图时 / 当视图即将从父视图移除时调用
- (void)willMoveToSuperview:(nullable UIView *)newSuperview{
[super willMoveToSuperview:newSuperview];
[self continue];
}
3.4 当视图加入父视图时 / 当视图从父视图移除时调用
- (void)didMoveToSuperview{
[super didMoveToSuperview];
[self continue];
}
3.5 当视图即将加入window视图时 / 当视图即将从window视图移除时调用
- (void)willMoveToWindow:(nullable UIWindow *)newWindow{
[super willMoveToWindow:newWindow];
[self continue];
}
3.6 当视图加入window视图时 / 当视图从window视图移除时调用
- (void)didMoveToWindow{
[super didMoveToWindow];
[self continue];
}