Skip to content

Instantly share code, notes, and snippets.

Created January 8, 2018 21:18
Show Gist options
  • Save anonymous/41f98c7ec4ed2ebb7f23dd14681ba9a9 to your computer and use it in GitHub Desktop.
Save anonymous/41f98c7ec4ed2ebb7f23dd14681ba9a9 to your computer and use it in GitHub Desktop.
SWIFT: Extend UIView to add fadeIn() and fadeOut() functions
import Foundation
import UIKit
extension UIView {
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) }
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