iOS LaunchScreen 和自定义加载页 2016
写在前面
公司今天突然给了一个需求,要求在APP前添加一个启动页面,页面上要带有倒计时Button,点击倒计时Button跳过该页面,倒计时完成,页面消失。一开始还以为就是一个简单的launchScreen,后来在写的时候发现launchScreen.storyboard/launchScreen.xib只能加载静态页面,如果想要添加一个有交互的页面(动态页面),必须自定义,并在application.m文件中添加。下面给出LuanchScreen的添加方法,以及自定义页面的方式。
LuanchScreen
1.在launchScreen.storyboard / launchScreen.xib中添加
2.使用LaunchImage
3.自定义
程序运行起来,欢迎界面之后,会进入AppDelegate,因此我们可以在application: didFinishLaunchingWithOptions:添加代码完成想要的效果。连网获取图片可以用第三方SDWebImage实现,所以需要先将第三方文件夹导入。因为显示广告的页面是在欢迎界面基础上显示的,因此可以直接利用LaunchScreen.xib中得view,在上面添加一个UIImageView显示图片,然后将其加在window上,并显示在最上层。广告图片显示之后,再将view移除掉,显示程序的主界面。
代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]];
[self.window makeKeyAndVisible];
LaunchScreenView *advertiseView = [[LaunchScreenView alloc] initWithFrame:self.window.bounds];
[advertiseView show];
[self.window makeKeyAndVisible];
}