当前位置:   article > 正文

IOS开发学习日记(十五)

IOS开发学习日记(十五)

目录

App启动过程及生命周期

App的启动

UIApplication

 UIApplicationDelegate

 通过App生命周期回调实现启动页

 闪屏的实现

简单实现闪屏功能

App启动过程及生命周期

App的启动

·main函数前

        动态链接 / 二进制文件加载 / runtime / 类的加载 ......

·main函数

  1. int main(int argc, char * argv[]) {
  2. NSString * appDelegateClassName;
  3. @autoreleasepool {
  4. // Setup code that might create autoreleased objects goes here.
  5. appDelegateClassName = NSStringFromClass([AppDelegate class]);
  6. }
  7. return UIApplicationMain(argc, argv, nil, appDelegateClassName);
  8. }

创建UIApplication对象(系统功能) 创建对应的delegate实现业务逻辑

UIApplication

·处理App生命周期 / 系统内存警告

·处理UI / statusbar / 图标消息数等状态的变化 / 方向

·处理openURL

·提供Delegate / Notification两种方式处理业务逻辑

·根据App状态调整业务逻辑

         ·Not running

        ·Inactive:中间的过渡状态

        ·Active:正在前台运行,系统分配更多资源

        ·Background:分配较少的资源

        ·Suspended:内存不足系统自动Kill      

 UIApplicationDelegate

 通过App生命周期回调实现启动页

 闪屏的实现

·启动前图片的组成

        ·Launch Screen + Splash Screen

·Launch Screen启动屏(系统级)

        ·是Main函数之前 + didFinishLaunch前

        ·系统启动App时自动展示

        ·在准备好App UI数据后自动消失

        ·给用户以响应,确定点击了正确的图标

·Splash Screen闪屏(业务逻辑)

        ·Launch Screen展示时间短,看不清

        ·实现同样的图片,显示图标等信息

        ·实现广告 / 推广活动页面

        ·实现游戏中Loading页面

使用Xcode配置图片:

        ·分别上传对应设备2x 3x的图片

        ·系统自动展示和消失

直接在当前Window上addSubview

页面结构保证在最上面

创建新的Window成为KeyWindow

调整window的level

多Window的管理 

简单实现闪屏功能

点击跳过或三秒钟后自动跳过

  1. //
  2. // GSCSplashView.m
  3. // GSCApp1
  4. //
  5. // Created by gsc on 2024/6/15.
  6. //
  7. #import "GSCSplashView.h"
  8. #import "GSCScreen.h"
  9. @interface GSCSplashView()
  10. @property(nonatomic,strong,readwrite)UIButton *button;
  11. @property(nonatomic,strong,readwrite)NSTimer *timer;
  12. @end
  13. @implementation GSCSplashView
  14. -(instancetype)initWithFrame:(CGRect)frame{
  15. self = [super initWithFrame:frame];
  16. if(self){
  17. self.image = [UIImage imageNamed:@"icon.bundle/splash.png"];
  18. [self addSubview:({
  19. _button = [[UIButton alloc] initWithFrame:UIRectAdapter(330, 100, 60, 40)];
  20. _button.backgroundColor = [UIColor lightGrayColor];
  21. [_button setTitle:@"跳过" forState:UIControlStateNormal];
  22. [_button addTarget:self action:@selector(_removeSplashView) forControlEvents:UIControlEventTouchUpInside];
  23. _timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(_removeSplashView) userInfo:nil repeats:NO];
  24. _button;
  25. })];
  26. self.userInteractionEnabled = YES;
  27. }
  28. return self;
  29. }
  30. #pragma mark -
  31. -(void)_removeSplashView{
  32. [self removeFromSuperview];
  33. }
  34. @end

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/746272
推荐阅读
相关标签
  

闽ICP备14008679号