请选择 进入手机版 | 继续访问电脑版

iOS应用程序生命周期

[复制链接]
阿峻 发表于 2021-1-1 17:46:23 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
1.应用程序生命周期(AppDelegate)
(1.点击应用程序图标
(2.程序入口:进入Main函数
(3.通过UIApplicationMain函数
(4.初始化UIApplication对象而且设置代理对象AppDelegate
(5.程序完成加载:[AppDelegate application:didFinishLaunchingWithOptions:]
(6.创建Window窗口:UIWindow
(7.程序被激活:[AppDelegate applicationDidBecomeActive:]
(8.点击Home键
(1)程序取消激活状态:[AppDelegate applicationWillResignActive:]
(2)程序进入配景:[AppDelegate applicationDidEnterBackground:]
(9.点击应用图标
(1)程序进入前台:[AppDelegate applicationWillEnterForeground:]
(2)程序被激活:[AppDelegate applicationDidBecomeActive:]
(10.内存告诫:[AppDelegate applicationDidReceiveMemoryWarning]
(11.将要终止:[AppDelegate applicationWillTerminate]
  1. #pragma mark 在应用程序加载完毕之后调用- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.    NSLog(@"应用程序启动");    return YES;}- (void)applicationWillResignActive:(UIApplication *)application{    NSLog(@"即将从前台进入配景");}- (void)applicationDidEnterBackground:(UIApplication *)application{    NSLog(@"已经从前台进入配景");}- (void)applicationWillEnterForeground:(UIApplication *)application{    NSLog(@"即将从配景进入前台");}- (void)applicationDidBecomeActive:(UIApplication *)application{    NSLog(@"已经从配景进入前台");}- (void)applicationWillTerminate:(UIApplication *)application{    NSLog(@"应用程序被杀死或关闭");}
复制代码
2.控制器生命周期(UIViewController)
  1. - (instancetype)init{    if (self = [super init]) {        NSLog(@"1.init初始化");    }    return self;}//其时xib加载时- (void)awakeFromNib{    [super awakeFromNib];    NSLog(@"2.Nib加载乐成");}- (void)loadView{    [super loadView];    NSLog(@"3.加载view。");}- (void)viewDidLoad {    [super viewDidLoad];    NSLog(@"4.载入完成,可以进行自界说数据以及动态创建其他控件");}- (void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    NSLog(@"5.视图将出现在屏幕之前");}- (void)viewWillLayoutSubviews{    [super viewWillLayoutSubviews];    NSLog(@"6.将要对子视图进行调解");}- (void)viewDidLayoutSubviews{    [super viewDidLayoutSubviews];    NSLog(@"7.对子视图进行调解完毕");}- (void)viewDidAppear:(BOOL)animated{    [super viewDidAppear:animated];    NSLog(@"8.视图已在屏幕上渲染完成");}- (void)viewWillDisappear:(BOOL)animated{    [super viewWillDisappear:animated];    NSLog(@"9.视图将被从屏幕上移除");}- (void)viewDidDisappear:(BOOL)animated{    [super viewDidDisappear:animated];    NSLog(@"10.视图已经被从屏幕上移除");}- (void)dealloc{    NSLog(@"11.视图被销毁,此处需要对你在init和viewDidLoad中创建的对象进行释放");}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    NSLog(@"12.内存告诫");}
复制代码
3.View生命周期(UIView)
  1. - (void)didAddSubview:(UIView *)subview{    [super didAddSubview:subview];    NSLog(@"1.当视图添加子视图时调用");}- (void)willRemoveSubview:(UIView *)subview{    [super willRemoveSubview:subview];    NSLog(@"2.当子视图从本视图移除时调用");}- (void)willMoveToSuperview:(nullable UIView *)newSuperview{    [super willMoveToSuperview:newSuperview];    NSLog(@"3.当视图即将加入父视图时 / 当视图即将从父视图移除时调用");}- (void)didMoveToSuperview{    [super didMoveToSuperview];    NSLog(@"4.当视图加入父视图时 / 当视图从父视图移除时调用");}- (void)willMoveToWindow:(nullable UIWindow *)newWindow{    [super willMoveToWindow:newWindow];    NSLog(@"5.当视图即将加入window视图时 / 当视图即将从window视图移除时调用");}- (void)didMoveToWindow{    [super didMoveToWindow];    NSLog(@"6.当视图加入window视图时 / 当视图从window视图移除时调用");}
复制代码
 

来源:https://blog.csdn.net/fanyun_01/article/details/111877601
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


专注素材教程免费分享
全国免费热线电话

18768367769

周一至周日9:00-23:00

反馈建议

27428564@qq.com 在线QQ咨询

扫描二维码关注我们

Powered by Discuz! X3.4© 2001-2013 Comsenz Inc.( 蜀ICP备2021001884号-1 )