iOS 第三方框架-SDWebImage

1> 如何防止一个url对应的图片重复下载
* 查看“基本处理原理”上图
2> SDWebImage的默认缓存时长是多少?
* 1个星期
3> SDWebImage底层是怎么实现的?
* 查看“基本处理原理”上图
常用方法
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
SDWebImageOptions 参数说明
- SDWebImageRetryFailed : 下载失败后,会自动重新下载
- SDWebImageLowPriority : 当正在进行UI交互时,自动暂停内部的一些下载操作
- SDWebImageRetryFailed | SDWebImageLowPriority : 拥有上面2个功能
我们使用的时候,一般就是用第3点。实例如:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ID = @"app";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
} // 取出模型
HMApp *app = self.apps[indexPath.row]; // 设置基本信息
cell.textLabel.text = app.name;
cell.detailTextLabel.text = app.download; // 下载图片
NSURL *url = [NSURL URLWithString:app.icon];
UIImage *placeholder = [UIImage imageNamed:@"placeholder"]; SDWebImageOptions options = SDWebImageRetryFailed | SDWebImageLowPriority; [cell.imageView sd_setImageWithURL:url placeholderImage:placeholder options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) { // 这个block可能会被调用多次
NSLog(@"下载进度:%f", (double)receivedSize / expectedSize);
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
NSLog(@"----图片加载完毕---%@", image);
}];
return cell;
}
内存处理
/**
* 当app接收到内存警告
*/
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
SDWebImageManager *mgr = [SDWebImageManager sharedManager]; // 1.取消正在下载的操作
[mgr cancelAll]; // 2.清除内存缓存
[mgr.imageCache clearMemory];
}
iOS 第三方框架-SDWebImage的更多相关文章
- iOS:第三方框架MJPhotoBrowser图片浏览器的使用
介绍:MJPhotoBrowser这个第三方库是MJ老师封装的一套用来浏览图片的浏览器,可是是本地图片.网络图片.gif图片等,其也依赖了SDWebImage.SVProgressHUD.YLGIFI ...
- iso中第三方框架SDWebImage的使用步骤
一.SDWebImage的使用 1.依赖的框架 * ImageIO.framework * MapKit.framework 2.UIImageView下载图片需要的头文件:UIImageView+W ...
- iOS 第三方框架-Masonry
介绍地址:http://www.cocoachina.com/ios/20141219/10702.html 官网:https://github.com/SnapKit/Masonry 记住:一定要先 ...
- iOS 第三方框架-MJRefresh
MJRefresh是一款非常好用的上拉下拉第三方库,使用也很简单.github地址: https://github.com/CoderMJLee/MJRefresh . 下拉刷新 官方给过来的例子很简 ...
- IOS第三方之SDWebImage
项目中从服务器端下载图片这些几乎是必备的,使用时也很简单,只需引入SDWebImage文件 // // ViewController.m // sdWebImageDemo // // Created ...
- iOS - 第三方框架 - AFN
#5.AFNetworking 2.6使用方法 >2.6版本 支持 iOS7以上,而且支持NSURLConnectionOperation >3.0版本 支持 iOS7以上 NSURLCo ...
- iOS 第三方框架-MJExtension
1.数组转换成模型数组 // 将 "微博字典"数组 转为 "微博模型"数组 NSArray *newStatuses = [HWStatus objectArr ...
- iOS 第三方框架-MBProgressHUD
MBProgressHUD提示框官网地址:https://github.com/jdg/MBProgressHUD 官网里已经提供了足够多的例子供我们使用,但在实现开发中,我们用到的只是其中的一小部分 ...
- ios开发清除SDWebImage图片缓存
一:一般在实际的项目应用中都会用到第三方框架SDWebImage去下载缓存图片,但在ios开发应用中,常常涉及对SDWebImage缓存图片的清除.本文所列出代码即是对SDWebImage缓存图片的清 ...
随机推荐
- content-type对照表
- WPF 依赖属性和附加属性
依赖属性: 依赖属性就是自己没有值,通过Binding从数据源获得值,就是依赖在别人身上,拥有依赖属性的对象称为依赖对象. 依赖属性的值存在哪里? 在WPF运行时,维护了一个全局的Hashtable存 ...
- i-chips融合芯片分析
适合做图像变形和融合 http://www.i-chips.co.jp/products/ma_non-deployment/c786.html 下面视频其实用了2个芯片,其中IP00C733用原始信 ...
- LeetCode 509 Fibonacci Number 解题报告
题目要求 The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, su ...
- storm配置文件
- 1、python接口测试requests
import requestsimport jsonr=requests.get('http://www.baidu.com') #get 请求方式r=r ...
- Linux命令小计
一.yum和apt-get的区别 Linux系统下安装包格式有:rpm包和deb包. pm包主要应用在RedHat系列包括 Fedora等发行版的Linux系统上 deb包主要应用于Debian系列包 ...
- linux清空历史记录
前几天弄了个Linux服务器做网站,发现在不同终端登陆时,上下键都会出现一堆无用的命令,搜了一下解决方法,做个笔记. 在Linux中,每个用户目录下都有一个.bash_history文件用于保存历史命 ...
- tomcat去掉项目名称
进入tomcat的conf目录,查看server.xml,找到<Host></Host>,在里面添加<Context path="" docBase= ...
- Vue 通过 Lodash 限制操作频率
<template> <div id="watch-example"> <p> Ask a yes/no question: <input ...