用最通俗易懂的話概括SDWebImage實(shí)現(xiàn)過程
首先展示默認(rèn)圖嚣崭,然后根據(jù)得到的URL處理圖片
在緩存中查找圖片是否以及存在井誉,存在的話直接展示
不存在的話禀梳,在硬盤中查找圖片是否存在浓冒,存在的話先放到緩存再進(jìn)行展示
硬盤中也不存在圖片,根據(jù)URL下載圖片笔刹,
下載完成后進(jìn)行解碼,展示冬耿,存入緩存和硬盤
SDWebImage使用
//最基本的使用
[self.image sd_setImageWithURL:imagePath];
//使用block舌菜,加載完圖片后進(jìn)行一定的操作
[self.image sd_setImageWithURL:imagePath completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
dosomething;
}];
//給默認(rèn)圖片
[self.image sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"]];
//使用默認(rèn)圖片和block
[self.image sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
dosomething;
}];
//選擇方式
[self.image sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"] options:SDWebImageRetryFailed];
小白總結(jié),歡迎打臉指正