使用SDWebimage加載圖片,添加漸進動畫方式:
1.找到UIView+WebCache.m
2.143行 if(iage){ 【用如下代碼替換】}? 括號內用如下代碼替換
? ? ? ? ? ? ? ? CATransition *animation = [CATransition animation];
? ? ? ? ? ? ? ? animation.duration = .85f;
? ? ? ? ? ? ? ? animation.type = kCATransitionFade;
? ? ? ? ? ? ? ? animation.removedOnCompletion = YES;
? ? ? ? ? ? ? ? [self.layer addAnimation:animation forKey:@"transition"];
? ? ? ? ? ? ? ? targetImage= image;
? ? ? ? ? ? ? ? targetData = data;
? ? ? ? ? ? ? ? [self setNeedsLayout];
3.在 [self sd_setImageLoadOperation:operation forKey:validOperationKey] 方法上面添加[self.layer removeAnimationForKey:@"transition"];用以移除添加的漸進動畫
效果如下:
SDWebimage 加載圖片漸變