Image gradients can be implemented in two ways:

#import “UIView+ webcache. h” and add it in 136 lines of code.

CATransition *animation = [CATransition animation]; Animation. Duration = 0.50 f; animation.type = kCATransitionFade; animation.removedOnCompletion = YES; [wself.layer addAnimation:animationforKey:@"transition"];
[wself setNeedsLayout];Copy the code

As shown in figure:



Method 2: in sd_setImageWithURL: placeholderImage: completed: method, adding CATransition images loaded block, this approach is best encapsulation, the place for the image used for a project or a lot

 [self.imageView sd_setImageWithURL:[NSURL URLWithString:albumModel.albumImg] placeholderImage:placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {       
 if(image) { CATransition *animation = [CATransition animation]; Animation. Duration = 2.0; animation.type = kCATransitionFade; animation.removedOnCompletion = YES; [self.imageView.layer addAnimation:animationforKey:@"transition"]; }}];Copy the code


There are several other types of CATransition attribute type:

  1. KCATransitionFade // Cross fade transition
  2. KCATransitionMoveIn // Move overwrite original image
  3. KCATransitionPush // The new view pushes out the old view
  4. KCATransitionReveal // the bottom shows