IOS网络图片缓存之SDWebImage
2016-08-09 17:23
555 查看
加载网络图片可以说是网络应用中必备的。如果单纯的去下载图片,而不去做多线程、缓存等技术去优化,加载图片时的效果与用户体验就会很差。
处理网络图片缓存步骤:
1、根据图片URL查找内存是否有这张图片,有则返回图片,没有则进入下一步。
2、查找本地磁盘存储是否有这张图片,有则返回图片,没有进行下一步。
3、从网络上下载该图片,下载完后保存到内存和本地磁盘存储上,并返回该图片。
使用第三方框架SDWebImage
特点:
1、依赖库很少,功能全面
2、自动实现磁盘缓存
3、缓存图片名字是以MD5进行加密的后缀名进行命名
4、只需要一个方法就可以实现多线程&带缓冲等效果
使用SDWebImage 方法实现缓存图片功能
SDWebImage中的一些参数 修改:
*SDWebImageRetryFailed = 1<< 0, 默认选项,失败后重试
*SDWebImageLowPriority = 1<< 1, 使用低优先级
*SDWebImageCacheMemoryOnly = 1<< 2, 仅仅使用内存缓存
*SDWebImageProgressiveDownload = 1<< 3, 显示现在进度
*SDWebImageRefreshCached = 1<< 4, 刷新缓存
*SDWebImageContinueInBackground =1 << 5, 后台继续下载图像
*SDWebImageHandleCookies = 1<< 6, 处理Cookie
*SDWebImageAllowInvalidSSLCertificates= 1 << 7, 允许无效的SSL验证
*SDWebImageHighPriority = 1<< 8, 高优先级
*SDWebImageDelayPlaceholder = 1<< 9 延迟显示占位图片
处理网络图片缓存步骤:
1、根据图片URL查找内存是否有这张图片,有则返回图片,没有则进入下一步。
2、查找本地磁盘存储是否有这张图片,有则返回图片,没有进行下一步。
3、从网络上下载该图片,下载完后保存到内存和本地磁盘存储上,并返回该图片。
使用第三方框架SDWebImage
特点:
1、依赖库很少,功能全面
2、自动实现磁盘缓存
3、缓存图片名字是以MD5进行加密的后缀名进行命名
4、只需要一个方法就可以实现多线程&带缓冲等效果
使用SDWebImage 方法实现缓存图片功能
#pragma mark - 数据源方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.appList.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; //用模型来填充每个cell XNApp *app = self.appList[indexPath.row]; cell.textLabel.text = app.name; //设置文字 //使用SDWebImage来完成上面的功能. 针对ImageView. //一句话, 自动实现了异步下载. 图片本地缓存. 网络下载. 自动设置占位符. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:app.icon] placeholderImage:[UIImage imageNamed:@"user_default"]]; return cell; }
SDWebImage中的一些参数 修改:
*SDWebImageRetryFailed = 1<< 0, 默认选项,失败后重试
*SDWebImageLowPriority = 1<< 1, 使用低优先级
*SDWebImageCacheMemoryOnly = 1<< 2, 仅仅使用内存缓存
*SDWebImageProgressiveDownload = 1<< 3, 显示现在进度
*SDWebImageRefreshCached = 1<< 4, 刷新缓存
*SDWebImageContinueInBackground =1 << 5, 后台继续下载图像
*SDWebImageHandleCookies = 1<< 6, 处理Cookie
*SDWebImageAllowInvalidSSLCertificates= 1 << 7, 允许无效的SSL验证
*SDWebImageHighPriority = 1<< 8, 高优先级
*SDWebImageDelayPlaceholder = 1<< 9 延迟显示占位图片
相关文章推荐
- iOS网络图片缓存SDWebImage
- iOS网络编程(三) 异步加载及缓存图片---->SDWebImage
- iOS网络编程(三) 异步加载及缓存图片---->SDWebImage
- iOS网络编程(三) 异步加载及缓存图片---->SDWebImage
- 【iOS】网络载入图片缓存与SDWebImage
- iOS网络加载图片缓存与SDWebImage
- 检测SDWebImage有没有缓存图片 IOS 获取网络图片大小
- iOS网络编程(三) 异步加载及缓存图片---->SDWebImage
- 【iOS】网络加载图片缓存与SDWebImage
- 检测SDWebImage有没有缓存图片 IOS 获取网络图片大小
- iOS网络编程(三) 异步加载及缓存图片---->SDWebImage
- 【iOS】网络加载图片缓存与SDWebImage
- iOS 下载缓存网络图片 SDWebImage
- 【iOS】网络加载图片缓存与SDWebImage
- IOS 使用SDWebImage清除图片缓存
- iOS UITableViewCell 多线程 网络+沙盒的图片加载以及第三方框架SDWebImage方式加载
- SDWebImage 异步加载网络图片 缓存…
- iOS第三方网络图片加载- SDWebImage笔记(转)
- IOS开发笔记 - 基于SDWebImage的网络图片加载处理
- iOS 图片缓存框架SDWebImage使用方法(欢迎提建议和分享遇到的问题)