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缓存图片的清 ...
随机推荐
- JS 通过字符串取得对应对象
//对Array的扩展,查找所有满足条件的元素 Array.prototype.findAll = function (match) { var tmp = []; for (var i = 0; i ...
- CH 1601 - 前缀统计 - [字典树模板题]
题目链接:传送门 描述给定 $N$ 个字符串 $S_1,S_2,\cdots,S_N$,接下来进行 $M$ 次询问,每次询问给定一个字符串 $T$,求 $S_1 \sim S_N$ 中有多少个字符串是 ...
- [No0000F5]C# 类(Class)
当你定义一个类时,你定义了一个数据类型的蓝图.这实际上并没有定义任何的数据,但它定义了类的名称意味着什么,也就是说,类的对象由什么组成及在这个对象上可执行什么操作.对象是类的实例.构成类的方法和变量成 ...
- JSCS: Please specify path to 'JSCS' package
JSCS: Please specify path to 'JSCS' package 1.webStrom提示: JSCS: Please specify path to 'JSCS' packag ...
- Lombok安装及使用
为什么要使用Lombok: 虽然一般的IDE(eclipse,Intellij)都有自动生成代码的功能,如:生成setter,getter,toString,equels,hashcode等.但是如果 ...
- role="navigation"
HTML5的标签属性,可以用于标识一个普通的标签,使之语义化,方便浏览器对其具体功能进行识别. 例如div容器制作的导航栏,加上role="navigation",就可以让浏览器知 ...
- window.location.reload(false);window.location.reload(true);history.Go(0)区别
在日常工作中常用的页面刷新方式的区别: 1 window.location.reload(false); 先说说window.location.reload(false);当我们window.loc ...
- mac下安装debug坑
mac默认情况下的php版本是很低的,当你直接用phpize的时候默认是使用mac默认安装的phpize版本,这个时候查看Phpinfo的时候是看不到xdebug的,这时候查看错误日志会收到这样的报错 ...
- ios开发dismiss所有控制器
-(void)dismissToRootViewController { UIViewController *vc = self; while (vc.presentingViewController ...
- centos中文语言安装
1.查看当前使用的系统语言 #echo LANG 2.查看系统是否安装中文 #locale 如有zh_cn,表示已经安装了中文语言 3.安装中文 #yum groupinstall chinese-s ...