Created
September 13, 2017 12:14
-
-
Save Th3nion/d1d569e3b51f3203b1da601c9a2968c0 to your computer and use it in GitHub Desktop.
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
// | |
// UIImage+replaceImage.swift | |
// | |
// Created by mtournier on 26/10/16. | |
// NO Copyright ! | |
// | |
import Foundation | |
import UIKit | |
extension UIImageView { | |
/// Change the image inside ImageView with a fade animation | |
/// | |
/// - Parameters: | |
/// - image: the new image to display | |
/// - animated: activate fade or not | |
func replaceImage(_ image:UIImage, animated:Bool) { | |
if animated { | |
let animationDuration:TimeInterval = 0.25 | |
CATransaction.begin() | |
CATransaction.setAnimationDuration(animationDuration) | |
let transition = CATransition() | |
transition.type = kCATransitionFade | |
self.layer.add(transition, forKey: kCATransition) | |
self.image = image | |
CATransaction.commit() | |
} else { | |
self.image = image | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment