发表日期:2016-04 文章编辑:小灯 浏览次数:1215
demo:https://github.com/Flying-Einstein/LaunchScreenTest喜欢就给个star吧
静态图类型 :微信
微信.gif 图片不变,有动画效果 :京东
京东.gif
网易公开课 |
百度云.gif
有道词典.gif 静态图类型 :这种比较简单,开发者可以使用LaunchImage和LaunchScreen.storyboard的任何一种方式添加所需的正确格式的图片,但是在使用的过程中需要注意的事项,读者可以看我的这篇文章LaunchImage和LaunchScreen.xib混用出现的坑
图片不变,有动画效果 :这种方式,笔者认为在实现方式上和第三种是一样的,就不在赘述,感兴趣的读者在看完第三种实现方式后,可以尝试去做。
随着节日或者时间动态更换的 :这种方式,也就是笔者今天着重要讲的,原理及实现方式。
1.pic.jpg
2.pic.jpg第一张图片是内容兼容性很强的图片,就是一个版权说明加上一个类似于app logo的样式,上面空白部分可以根据节日的不同,调整展示的样式 关于猜测的一点验证?
百度云的包,我们先来看第一张截图
屏幕快照 2016-04-12 下午6.25.55.png 这是一个post的请求方式,可以看到在url路径中,有image/diff这段,笔者判断这段路径返回 的参数是用来决定是否更换第二张图片的
我们再来看第二张截图
屏幕快照 2016-04-12 下午6.26.19.png紧接着第一次网络请求,就进行了这次网络请求,我们在path路径下可以看到app.gif,笔者认为这个网址就是图片的地址,百度云的第二张图片有动画效果,笔者猜测可能是gif格式的图片
UIViewController *viewController = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LaunchScreen"]; UIView *launchView = viewController.view; UIImageView* Imageview= [[UIImageViewalloc]initWithFrame:[UIScreen mainScreen].bounds]; [launchView addSubview:Imageview]; [self.view addSubview:launchView]; ** 这一步是获取上次网络请求下来的图片,如果存在就展示该图片,如果不存在就展示本地保存的名为test的图片**
NSMutableData * data = [[NSUserDefaults standardUserDefaults]objectForKey:@"imageu"]; if (data.length>0) {Imageview.image = [UIImage imageWithData:data]; }else{ Imageview.image = [UIImage imageNamed:@"Test"]; } ** 下面这段代码,是调用AFN下载文件的方法,异步方式下载,但是在这里异步方式下载有一个问题,就是这次下载完成的图片,下次启动时才会展示,读者可以换成同步的,但是同步下载会有时间延迟,用户体验不好,下载完图片后,将图片以二进制的形式存在本地,笔者用的是userdefault,这是不科学的,读者可以存在其他文件夹,**
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; NSURL *URL = [NSURL URLWithString:@"http://s16.sinaimg.cn/large/005vePOgzy70Rd3a9pJdf&690"]; NSURLRequest *request = [NSURLRequest requestWithURL:URL]; NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]]; } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) { NSLog(@"File downloaded to: %@", filePath);NSData * image = [NSData dataWithContentsOfURL:filePath]; [[NSUserDefaults standardUserDefaults]setObject:image forKey:@"imageu"];}]; [downloadTask resume]; ** 这段代码,可以实现第二张图片有3D的动画效果,动画结束后,进行同步的网络请求,请求的是广告页图片,之所以用同步的是因为,如果用同步的话主页面显示后,图片才会加载完成显示。**
[UIView animateWithDuration:6.0f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{//launchView.alpha = 0.0f; launchView.layer.transform = CATransform3DScale(CATransform3DIdentity, 1.5f, 1.5f, 1.0f); } completion:^(BOOL finished) { NSString * ad_imgUrl= @"http://www.uimaker.com/uploads/allimg/121217/1_121217093327_1.jpg"; AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [BBLaunchAdMonitor showAdAtPath:ad_imgUrlonView:appDelegate.window.rootViewController.viewtimeInterval:5detailParameters:@{@"carId":@(12345), @"name":@"奥迪-品质生活"}];[launchView removeFromSuperview]; }];
demo.gif这是笔者的实现过程,希望可以给读者一点思路,如果读者觉得有什么不明白的,或者有更好的方式,希望能联系笔者,或者在评论中给出建议。
如有转载,请告知笔者