美文网首页
iOS 启动页实现方案

iOS 启动页实现方案

作者: ios小蜗牛 | 来源:发表于2020-05-27 11:26 被阅读0次

启动页的定位

1.由于每次打开都能看到,因此启动页常用于广告位,为产品带来盈利。
2.用来判断是跳转主页面还是登陆界面。
3.用来缓冲app的加载时间。

实现思路

在didFinishLaunchingWithOptions里面创建两个Window,一个是主Window,一个是启动页Window,启动页用来判断是跳转主页面还是登陆界面。
如果是登录状态,那么在规定时间内销毁启动页window,展示主Window。
如果不是登录状态,那么就从引导页跳转登录界面,登录成功后在销毁启动页Window。

优点

1.降低耦合性。
2.不用修改框架的结构。
3.根控制器不变。

实现代码

#import "AppDelegate.h"
#import "ViewController.h"
#import "StyleViewController.h"

@interface AppDelegate ()

/**  */
@property (nonatomic, strong) UIWindow *styleWindow;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    // 创建主window
    [self styleOne];
    
    // 创建引导页window
    [self styleTwo];
  
    return YES;
}


/**
 主window
 */
- (void)styleOne{
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = [[ViewController alloc] init];
    [self.window makeKeyAndVisible];
}


/**
 引导页window
 */
- (void)styleTwo{
    
    // 创建第二个window,遮挡住第一个window
    // 引导页的操作到StyleViewController控制器里面做
    self.styleWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.styleWindow.backgroundColor = [UIColor whiteColor];
    self.styleWindow.rootViewController = [[StyleViewController alloc] init];
    [self.styleWindow makeKeyAndVisible];

    // 定时销毁
    [self performSelector:@selector(cancelStyleWindow) withObject:nil afterDelay:5];
}


/**
 销毁引导页Window
 */
- (void)cancelStyleWindow{
    
    [self.styleWindow resignKeyWindow];
    self.styleWindow = nil;
}


@end

相关文章

网友评论

      本文标题:iOS 启动页实现方案

      本文链接:https://www.haomeiwen.com/subject/elfwahtx.html