iOS网络加载启动图
2016-07-27 15:59
351 查看
//这一步是获取LaunchScreen.storyboard里的UIViewController,UIViewController
的identifer是LaunchScreen
UIViewController
*viewController = [[UIStoryboard
storyboardWithName:@"LaunchScreen"
bundle:[NSBundle
mainBundle]]
instantiateViewControllerWithIdentifier:@"LaunchScreen"];
UIView
*launchView = viewController.view;
UIImageView * Imageview= [[UIImageView
alloc]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下载文件的方法,异步
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:3.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://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E5%9B%BE%E7%89%87&pn=0&spn=0&di=125546894880&pi=&rn=1&tn=baiduimagedetail&ie=utf-8&oe=utf-8&cl=2&lm=-1&cs=1003704465%2C1400426357&os=4246966059%2C4277404619&simid=4210997991%2C798394471&adpicid=0&ln=30&fr=ala&fm=&sme=&cg=&bdtype=0&oriquery=&objurl=http%3A%2F%2Fpic25.nipic.com%2F20121112%2F5955207_224247025000_2.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bgtrtv_z%26e3Bv54AzdH3Ffi5oAzdH3FnAzdH3F0nAzdH3F0al8l0mhdj9v1c9n_z%26e3Bip4s&gsm=0";
AppDelegate
*appDelegate = (AppDelegate
*)[[UIApplication
sharedApplication]
delegate];
[BBLaunchAdMonitor
showAdAtPath:ad_imgUrl
onView:appDelegate.window.rootViewController.view
timeInterval:5
detailParameters:@{@"carId":@(0001),
@"name":@"0007"}];
[launchView
removeFromSuperview];
}];
的identifer是LaunchScreen
UIViewController
*viewController = [[UIStoryboard
storyboardWithName:@"LaunchScreen"
bundle:[NSBundle
mainBundle]]
instantiateViewControllerWithIdentifier:@"LaunchScreen"];
UIView
*launchView = viewController.view;
UIImageView * Imageview= [[UIImageView
alloc]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下载文件的方法,异步
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:3.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://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E5%9B%BE%E7%89%87&pn=0&spn=0&di=125546894880&pi=&rn=1&tn=baiduimagedetail&ie=utf-8&oe=utf-8&cl=2&lm=-1&cs=1003704465%2C1400426357&os=4246966059%2C4277404619&simid=4210997991%2C798394471&adpicid=0&ln=30&fr=ala&fm=&sme=&cg=&bdtype=0&oriquery=&objurl=http%3A%2F%2Fpic25.nipic.com%2F20121112%2F5955207_224247025000_2.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bgtrtv_z%26e3Bv54AzdH3Ffi5oAzdH3FnAzdH3F0nAzdH3F0al8l0mhdj9v1c9n_z%26e3Bip4s&gsm=0";
AppDelegate
*appDelegate = (AppDelegate
*)[[UIApplication
sharedApplication]
delegate];
[BBLaunchAdMonitor
showAdAtPath:ad_imgUrl
onView:appDelegate.window.rootViewController.view
timeInterval:5
detailParameters:@{@"carId":@(0001),
@"name":@"0007"}];
[launchView
removeFromSuperview];
}];
相关文章推荐
- SSL协议(HTTPS) 握手、工作流程详解(双向HTTPS流程)
- TCP滑动窗口
- 混合结构
- socket编程之TCP服务器
- p2p结构
- HTTP与HTTPS的区别
- iOS开发工具-网络封包分析工具Charles
- 客户端/服务器结构
- 计算机网络的体系结构
- installing MPTCP
- vagrant入门教程--网络配置(9)
- poj2391(floyd+二分+网络流判定)
- 多线程调用HttpWebRequest并发连接限制
- RTSP - RTP over TCP
- 根据ip地址和掩码求网络地址,主机号,广播号和主机最大数。。
- CS231n 学习笔记(2)——神经网络 part2 :线性分类器,SVM
- HttpContext中保存上下文使用的参数
- [通过HttpWebRequest请求https接口]
- 通过HttpUrlConnection读取数据进行Pull解析
- SSL