Skip to content

Instantly share code, notes, and snippets.

@mansi-27
Created February 22, 2018 18:02
Show Gist options
  • Select an option

  • Save mansi-27/fae60895c6b15921a7efdf382c4f2bf4 to your computer and use it in GitHub Desktop.

Select an option

Save mansi-27/fae60895c6b15921a7efdf382c4f2bf4 to your computer and use it in GitHub Desktop.
Produce fade-in fade-out animation based on view's alpha
extension UIView {
/// Produce fade in animation
func fadeIn(_ duration: TimeInterval = 1.0, delay: TimeInterval = 0.0, completion: @escaping ((Bool) -> Void) = {(finished: Bool) -> Void in}) {
UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.alpha = 1.0
}, completion: completion)
}
/// Produce fadeout animation
func fadeOut(_ duration: TimeInterval = 1.0, delay: TimeInterval = 0.0, completion: @escaping (Bool) -> Void = {(finished: Bool) -> Void in}) {
UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.alpha = 0.0
}, completion: completion)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment