Skip to content

Instantly share code, notes, and snippets.

@5ZSQ
Created June 27, 2017 07:16
Show Gist options
  • Save 5ZSQ/18f0b3b17f42d96fecb82c51bc056740 to your computer and use it in GitHub Desktop.
Save 5ZSQ/18f0b3b17f42d96fecb82c51bc056740 to your computer and use it in GitHub Desktop.
iOS - 使用Core Animation中的CATranstion实现背景自然渐变
NSString *imgUrl = _dataArray[index][@"url"]; //下一张背景图url
UIImage *placeHolder = _baseImgView.image; //使用上一张背景图作为placeholder
[_baseImgView sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:placeHolder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (image)
CATransition *transition = [CATransition animation];
transition.type = kCATransitionFade;
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[_baseImgView.layer addAnimation:transition forKey:nil];
_baseImgView.image = [[image blurImage] jy_lucidImage];
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment