没有合适的资源?快使用搜索试试~ 我知道了~
文章目录类 方法 协议 分类解析SDWebImageOperation NSOperation的分类UIImageView+WebCache UIImageView分类UIView+WebCache UIView分类UIView+WebCacheOperation UIView分类SDWebImageCombinedOperation 继承自NSObjectSDWebImageManagerSDWebImageManagerDelegateSDImageCache 协议SDImageLoader 协议SDWebImageDownloader 下载类,此分类遵循SDImageLoa
资源推荐
资源详情
资源评论
SDWebImage解读解读
文章目录文章目录类 方法 协议 分类解析SDWebImageOperation NSOperation的分类UIImageView+WebCache UIImageView分类
UIView+WebCache UIView分类UIView+WebCacheOperation UIView分类SDWebImageCombinedOperation 继承自
NSObjectSDWebImageManagerSDWebImageManagerDelegateSDImageCache 协议SDImageLoader 协议
SDWebImageDownloader 下载类,此分类遵循SDImageLoader协议SDWebImageDownloadToken 每一个下载的关联对象,
可以取消下载操作 遵循SDWebImageOperation协议SDWebImageDownloaderOperation 下载工具类
SDImageCachesManager 缓存管理类 遵循 SDImageCache 协议SDImageCache 维护内存缓存和磁盘缓存SDMemoryCache
内存缓存类 继承NSCacheSDDiskCache 磁盘缓存类 继承NSObject总结
此部分会省略一些代码,请知晓 SD下载地址
类类 方法方法 协议协议 分类解析分类解析
SDWebImageOperation NSOperation的分类的分类
是NSOperation分类 遵循SDWebImageOperation 协议
@protocol SDWebImageOperation
- (void)cancel;
@end
@interface NSOperation (SDWebImageOperation)
@end
UIImageView+WebCache UIImageView分类分类
// 采用SDWebImage对UIImageView的对象加载图片的方法都会调用此方法
- (void)sd_setImageWithURL:(nullable NSURL *)url
placeholderImage:(nullable UIImage *)placeholder
options:(SDWebImageOptions)options
context:(nullable SDWebImageContext *)context
progress:(nullable SDImageLoaderProgressBlock)progressBlock
completed:(nullable SDExternalCompletionBlock)completedBlock {
// UIView+WebCache 内部方法
[self sd_internalSetImageWithURL:url
placeholderImage:placeholder
options:options
context:context
setImageBlock:nil
progress:progressBlock
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL *
_Nullable imageURL) {
if (completedBlock) {
completedBlock(image, error, cacheType, imageURL);
}
}];
UIView+WebCache UIView分类分类
因为此方法需要在需要在 UIButton 和 UIImageView 上重用 所以添加到它们的根类上
- (void)sd_internalSetImageWithURL:(nullable NSURL *)url
placeholderImage:(nullable UIImage *)placeholder
options:(SDWebImageOptions)options
context:(nullable SDWebImageContext *)context
setImageBlock:(nullable SDSetImageBlock)setImageBlock
progress:(nullable SDImageLoaderProgressBlock)progressBlock
completed:(nullable SDInternalCompletionBlock)completedBlock {
context = [context copy]; // copy to avoid mutable object
NSString *validOperationKey = context[SDWebImageContextSetImageOperationKey];
// SDOperationsDictionary对象中取出当前key对应的对象并取消所有操作 不会影响之后进行的下载操作
[self sd_cancelImageLoadOperationWithKey:validOperationKey];
if (!(options & SDWebImageDelayPlaceholder)) {
dispatch_main_async_safe(^{
[self sd_setImage:placeholder imageData:nil basedOnClassOrViaCustomSetImageBlock:setImageBlock cacheType:SDImageCacheTypeNone
imageURL:url];
});
}
if (url) {
SDWebImageManager *manager = context[SDWebImageContextCustomManager];
if (!manager) {
manager = [SDWebImageManager sharedManager];
}
SDImageLoaderProgressBlock combinedProgressBlock = ^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
if (imageProgress) {
imageProgress.totalUnitCount = expectedSize;
imageProgress.completedUnitCount = receivedSize;
}
if (progressBlock) {
progressBlock(receivedSize, expectedSize, targetURL);
}
};
@weakify(self);
// 请看SDWebImageManager部分 返回遵循SDWebImageOperation协议的对象 !!!
id operation = [manager loadImageWithURL:url options:options context:context progress:combinedProgressBlock completed:^(UIImage *image, NSData
*data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
@strongify(self);
if (!self) { return; }
// if the progress not been updated, mark it to complete state
if (imageProgress && finished && !error && imageProgress.totalUnitCount == 0 && imageProgress.completedUnitCount == 0) {
imageProgress.totalUnitCount = SDWebImageProgressUnitCountUnknown;
imageProgress.completedUnitCount = SDWebImageProgressUnitCountUnknown;
}
BOOL shouldCallCompletedBlock = finished || (options & SDWebImageAvoidAutoSetImage);
BOOL shouldNotSetImage = ((image && (options & SDWebImageAvoidAutoSetImage)) ||
(!image && !(options & SDWebImageDelayPlaceholder)));
SDWebImageNoParamsBlock callCompletedBlockClojure = ^{
if (!self) { return; }
if (!shouldNotSetImage) { // 刷新UI
[self sd_setNeedsLayout];
}
if (completedBlock && shouldCallCompletedBlock) {
completedBlock(image, data, error, cacheType, finished, url);
}
};
if (shouldNotSetImage) {
dispatch_main_async_safe(callCompletedBlockClojure);
return;
}
UIImage *targetImage = nil;
NSData *targetData = nil;
if (image) {
// case 2a: we got an image and the SDWebImageAvoidAutoSetImage is not set
targetImage = image;
targetData = data;
} else if (options & SDWebImageDelayPlaceholder) {
// case 2b: we got no image and the SDWebImageDelayPlaceholder flag is set
targetImage = placeholder;
targetData = nil;
}
// 设置图片
dispatch_main_async_safe(^{
[self sd_setImage:targetImage imageData:targetData basedOnClassOrViaCustomSetImageBlock:setImageBlock transition:transition
cacheType:cacheType imageURL:imageURL];
//#endif
callCompletedBlockClojure();
});
}];
// 添加到 SDOperationsDictionary 对象中添加一个键值对, 来表示操作的正在进行,它将 opertion 存储到 SDOperationsDictionary 中方便以后的 cancel.
[self sd_setImageLoadOperation:operation forKey:validOperationKey];
} else { // 错误处理}
}
- (void)sd_cancelImageLoadOperationWithKey:(nullable NSString *)key {
if (key) {
// Cancel in progress downloader from queue
SDOperationsDictionary *operationDictionary = [self sd_operationDictionary];
id operation;
@synchronized (self) {
operation = [operationDictionary objectForKey:key];
}
if (operation) {
if ([operation conformsToProtocol:@protocol(SDWebImageOperation)]) {
[operation cancel]; // 取消操作
}
@synchronized (self) {
[operationDictionary removeObjectForKey:key];
}
}
}
}
UIView+WebCacheOperation UIView分类分类
typedef NSMapTable<NSString *, id> SDOperationsDictionary; // 通过这种数据结构,存储操作
剩余11页未读,继续阅读
资源评论
weixin_38685961
- 粉丝: 8
- 资源: 907
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- ORACLE数据库管理系统体系结构中文WORD版最新版本
- Sybase数据库安装以及新建数据库中文WORD版最新版本
- tomcat6.0配置oracle数据库连接池中文WORD版最新版本
- hibernate连接oracle数据库中文WORD版最新版本
- MyEclipse连接MySQL的方法中文WORD版最新版本
- MyEclipse中配置Hibernate连接Oracle中文WORD版最新版本
- MyEclipseTomcatMySQL的环境搭建中文WORD版3.37MB最新版本
- hggm - 国密算法 SM2 SM3 SM4 SM9 ZUC Python实现完整代码-算法实现资源
- SQLITE操作入门中文WORD版最新版本
- Sqlite操作实例中文WORD版最新版本
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功