Added UIView extensions to animate alpha value.

This commit is contained in:
albert vila 2016-11-05 23:31:38 +01:00
parent 704a8231f6
commit a29aa5a5c3
1 changed files with 39 additions and 1 deletions

View File

@ -306,7 +306,6 @@ extension UIView {
transform = CATransform3DScale(transform, x, y, 1)
self.layer.transform = transform
}
}
// MARK: Layer Extensions
@ -597,3 +596,42 @@ extension UIView {
return parentView.rootView()
}
}
//MARK: Fade Extensions
private let UIViewFadeDuration: TimeInterval = 0.35
extension UIView {
///EZSE: Fade in with duration, delay and completion block.
public func fadeIn(_ duration:TimeInterval?, delay _delay:TimeInterval?, completion: ((Bool) -> Void)? = nil) {
UIView.animate(withDuration: duration ?? UIViewFadeDuration, delay: _delay ?? 0.0, options: UIViewAnimationOptions(rawValue: UInt(0)), animations: {
self.alpha = 0
}) { (success) in
if let completion = completion {
completion(success)
}
}
}
/// EZSwiftExtensions
public func fadeOut(_ duration:TimeInterval?, delay _delay:TimeInterval?, completion:((Bool) -> Void)? = nil) {
UIView.animate(withDuration: duration ?? UIViewFadeDuration, delay: _delay ?? 0.0, options: UIViewAnimationOptions(rawValue: UInt(0)), animations: {
self.alpha = 0
}) { (success) in
if let completion = completion {
completion(success)
}
}
}
/// Fade to specific value with duration, delay and completion block.
public func fadeToValue(_ value:CGFloat, duration _duration:TimeInterval?, delay _delay:TimeInterval?, completion:((Bool) -> Void)? = nil) {
UIView.animate(withDuration: _duration ?? UIViewFadeDuration, delay: _delay ?? 0.0, options: UIViewAnimationOptions(rawValue: UInt(0)), animations: {
self.alpha = value
}) { (success) in
if let completion = completion {
completion(success)
}
}
}
}