最近要做個(gè)需求 , 要把圖片漸漸的顯示效果
引入頭文件 , 做個(gè)分類搞定
代碼如下 :
#import"UIImageView+WebCache.h"
+ (void)loadImgWithPlaceholder:(UIImage *)placeImg url:(NSString *)urlStr imgView:(UIImageView *)imgView
{
[imgView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:placeImg completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if(error && !image)
{
return;
}
else
{
if(cacheType == SDImageCacheTypeNone)
{
//下載的
[UIView transitionWithView:imgView duration:0.5foptions:UIViewAnimationOptionTransitionCrossDissolve animations:^{
imgView.image = image;
} completion:NULL];
}
else
{
//內(nèi)存緩存中的
imgView.image = image;
}
}
}];
}