SDWebImage
1.SDWebImage框架的分析
SDWebImageManager管理者
//单例类方法,该方法提供一个全局的SDWebImageManager实例
+ (SDWebImageManager *)sharedManager;
//核心方法
- (id)downloadImageWithURL:(NSURL *)url
options:(SDWebImageOptions)options
progress:(SDWebImageDownloaderProgressBlock)progressBlock
completed:(SDWebImageCompletionWithFinishedBlock)completedBlock;
使用:
- (void)sd_setImageWithURL:(NSURL *)url;
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
[_bookImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.baidu.com"]] placeholderImage:[UIImage imageNamed:@"123.PNG"] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
NSLog(@"%f",1.0 * receivedSize/expectedSize);//打印下载进度
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
NSLog(@"回调返回缓存类型,0没有缓存?1内存缓存?2磁盘缓存?%zd",cacheType);//打印缓存类型
}];
//options枚举参数选项详细, 传0为默认
typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
//默认情况下,url在下载失败后,会加入黑名单,不会再次下载,使用该参数,url在下载失败后,不会加入黑名单,会再次下载
SDWebImageRetryFailed = 1 << 0, //失败后重新下载
//默认情况下,UI交互时也会启动图片下载,使用该参数,会推迟到滚动视图停止滚动后再继续下载,NSURLConnection的网络下载事件监听的运行循环模式是:NSDefaultRunloopMode
SDWebImageLowPriority = 1 << 1, //低优先级下载
//禁止磁盘缓存,只使用内存缓存
SDWebImageCacheMemoryOnly = 1 << 2, //只使用内存缓存
//图片从上到下依次显示,渐进式下载
SDWebImageProgressiveDownload = 1 << 3, //进度显示
//重新下载图片,不从内存,沙盒缓存里面去取,替换已有的缓存,缓存图像被刷新会调用一次completedBlock, 并传递最终图像
SDWebImageRefreshCached = 1 << 4, //刷新缓存
//系统进入后台,图片继续下载,如果后台任务过期,下载任务取消
SDWebImageContinueInBackground = 1 << 5, //后台下载
//处理保存在NSHTTPCookieStore中的cookies
SDWebImageHandleCookies = 1 << 6, //处理cookies
//允许不信任的SSL证书,主要用于测试使用
SDWebImageAllowInvalidSSLCertificates = 1 << 7, //允许不信任的SSL证书
//优先于默认队列中顺序下载
SDWebImageHighPriority = 1 << 8, //优先下载
//延迟加载占位图片
SDWebImageDelayPlaceholder = 1 << 9, //延迟加载占位图片
//
SDWebImageTransformAnimatedImage = 1 << 10,
};