美文网首页
SDWEbimage图片显示优化

SDWEbimage图片显示优化

作者: 坤哥爱卿 | 来源:发表于2017-07-11 11:32 被阅读84次

-(void)setItem:(CustomItem*)item{

_item= item;

//占位图片

UIImage*placeholder = [UIImageimageNamed:@"placeholderImage"];

//从内存\沙盒缓存中获得原图

UIImage*originalImage = [[SDImageCachesharedImageCache]imageFromDiskCacheForKey:item.originalImage];

if(originalImage) {

//如果内存\沙盒缓存有原图,那么就直接显示原图(不管现在是什么网络状态)

[self.mainImageViewsd_setImageWithURL:[NSURLURLWithString:item.originalImage]placeholderImage:placeholder];

}else{

//内存\沙盒缓存没有原图

AFNetworkReachabilityManager*mgr = [AFNetworkReachabilityManagersharedManager];

NSLog(@"%s,%d",__FUNCTION__,mgr.isReachableViaWiFi);

if(mgr.isReachableViaWiFi) {

//在使用Wifi,下载原图

[self.mainImageViewsd_setImageWithURL:[NSURLURLWithString:item.originalImage]placeholderImage:placeholder];

}elseif(mgr.isReachableViaWWAN) {

//在使用手机自带网络

#warning从沙盒中读取用户的配置项:在3G\4G环境是否仍然下载原图

BOOLalwaysDownloadOriginalImage = [[NSUserDefaultsstandardUserDefaults]boolForKey:@"alwaysDownloadOriginalImage"];

if(alwaysDownloadOriginalImage) {

//下载原图

[self.mainImageViewsd_setImageWithURL:[NSURLURLWithString:item.originalImage]placeholderImage:placeholder];

}else{

//下载小图

[self.mainImageViewsd_setImageWithURL:[NSURLURLWithString:item.thumbnailImage]placeholderImage:placeholder];

}

}else{

//没有网络

UIImage*thumbnailImage = [[SDImageCachesharedImageCache]imageFromDiskCacheForKey:item.thumbnailImage];

if(thumbnailImage) {

//内存\沙盒缓存中有小图

[self.mainImageViewsd_setImageWithURL:[NSURLURLWithString:item.thumbnailImage]placeholderImage:placeholder];

}else{

[self.mainImageViewsd_setImageWithURL:nilplaceholderImage:placeholder];

}

}

}

}

相关文章

网友评论

      本文标题:SDWEbimage图片显示优化

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