Created
July 21, 2017 02:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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