网络加载图片
来源:互联网 发布:云数据加密传输运营商 编辑:程序博客网 时间:2024/06/15 20:06
NSURL *imgUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",serverUrl,pic]]; //从服务器拿到图片的地址// NSLog(@"fsdf %@",imgUrl); if (hasCachedImage(imgUrl)) { imghead.image = [UIImage imageWithContentsOfFile:pathForURL(imgUrl)]; //看本地理由木有这张图片的缓存 }else { NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:imgUrl,@"url",imghead,@"imageView",nil]; [NSThread detachNewThreadSelector:@selector(cacheImage:) toTarget:[ImageCacher defaultCacher] withObject:dic]; }
<pre name="code" class="objc">-(void)cacheImage:(NSDictionary*)aDic{ NSURL *aURL=[aDic objectForKey:@"url"]; NSFileManager *fileManager=[NSFileManager defaultManager]; NSData *data=[NSData dataWithContentsOfURL:aURL] ; UIImage *image=[UIImage imageWithData:data]; if (image==nil) { return; } NSData *smallData=UIImagePNGRepresentation(image); NSLog(@"%@",pathInCacheDirectory(@"com.xmly")); NSString *pathStr = [NSString stringWithFormat:@"%@",pathInCacheDirectory(@"com.xmly")]; if (![fileManager fileExistsAtPath:pathStr]) { [fileManager createDirectoryAtPath:pathStr withIntermediateDirectories:YES attributes:Nil error:Nil]; } if (smallData) { [fileManager createFileAtPath:pathForURL(aURL) contents:smallData attributes:nil]; } UIButton *bt = [aDic objectForKey:@"uibtton"]; if (bt) { CATransition *transtion = [CATransition animation]; transtion.duration = 0.5; [transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [transtion setType:_type]; [transtion setSubtype:kCATransitionFromRight]; [bt.layer addAnimation:transtion forKey:@"transtionKey"]; [bt setImage:image forState:UIControlStateNormal]; UIGraphicsEndImageContext(); return; } UIView *view=[aDic objectForKey:@"imageView"]; //判断view是否还存在 如果tablecell已经移出屏幕会被回收 那么什么都不用做,下次滚到该cell 缓存已存在 不需要执行此方法 if (view!=nil) { CATransition *transtion = [CATransition animation]; transtion.duration = 0.5; [transtion setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [transtion setType:_type]; [transtion setSubtype:kCATransitionFromRight]; [view.layer addAnimation:transtion forKey:@"transtionKey"]; if ([[view class] isSubclassOfClass:[UIImageView class]]) { if ([[aDic objectForKey:@"type"] boolValue]) { view.backgroundColor = [UIColor clearColor]; [(UIImageView*)view setImage:[image grayscale:1]]; } else { view.backgroundColor = [UIColor clearColor]; [(UIImageView*)view setImage:image]; } } else { if ([aDic objectForKey:@"mohu1"] && [[aDic objectForKey:@"mohu1"] length] > 0) { view.layer.contents = (id)[image blurredImage:70].CGImage; view.contentMode = UIViewContentModeScaleToFill; } else if ([aDic objectForKey:@"mohu"] && [[aDic objectForKey:@"mohu"] length] > 0) { view.layer.contents = (id)[image blurredImage:70].CGImage; view.contentMode = UIViewContentModeScaleAspectFill; } else if ([aDic objectForKey:@"fill"] && [[aDic objectForKey:@"fill"] length] > 0) { view.layer.contents = (id)image.CGImage; view.contentMode = UIViewContentModeScaleAspectFill; } else { if ([[aDic objectForKey:@"type"] boolValue]) { view.backgroundColor = [UIColor colorWithPatternImage:[image grayscale:1]]; } else { view.backgroundColor = [UIColor colorWithPatternImage:image]; } } } } UIGraphicsEndImageContext(); }
1 0
- Delphi加载网络图片
- android加载网络图片
- 网络加载图片
- 加载网络图片
- 异步加载网络图片
- SDWebImage 加载网络图片
- 网络图片异步加载
- 异步加载网络图片
- Android加载网络图片
- android加载网络图片
- android 网络加载图片
- 异步加载网络图片
- 网络加载图片
- Flex加载网络图片
- swift 加载网络图片
- 网络加载图片
- ImageView加载网络图片
- 加载显示网络图片
- ubuntu14.04 配置安装 wineQQ 2013
- 顶级offer的标准:有内部培养+晋升机会
- Python Another Digest
- Linux应用札记【三】—Unity桌面环境使用技巧点滴
- ESQL查询之简单的Oracle数据库查询测试
- 网络加载图片
- cortex_m3_stm32嵌入式学习笔记(二十三):红外遥控实验(输入捕捉+解码)
- .net利用Attribute简单实现AOP
- BZOJ 1263 SCOI2006 整数划分 高精度
- 学习stanford公开课 Developing iOS8 Apps with Swift 笔记(一)
- Android将应用log信息保存文件
- CF D. Fox And Jumping
- 功率谱密度
- CF C.Guess Your Way Out!