Skip to content

Instantly share code, notes, and snippets.

@iAmrSalman
Created July 21, 2017 02:58
Show Gist options
  • Save iAmrSalman/eb5301291ddd2e1018005c94f8370ccd to your computer and use it in GitHub Desktop.
Save iAmrSalman/eb5301291ddd2e1018005c94f8370ccd to your computer and use it in GitHub Desktop.
[changeImage animation] UIImageView extension to fade in UIImageView new image #swift3 #image #animation #exttension
extension UIImageView {
func changeImage(to newImage: UIImage?) {
let crossFade: CABasicAnimation = CABasicAnimation(keyPath: "contents")
crossFade.duration = 0.2
crossFade.fromValue = self.image?.cgImage
crossFade.toValue = newImage?.cgImage
self.image = newImage
self.layer.add(crossFade, forKey: "animateContents")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment