Last active
November 22, 2017 10:53
-
-
Save srstanic/092685863c0ba3882778df5775264bfa to your computer and use it in GitHub Desktop.
Showing and hiding UIView
This file contains hidden or 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 UIView { | |
| func show(animated: Bool) { | |
| self.isHidden = false | |
| if animated { | |
| UIView.animate( | |
| withDuration: animationDuration, | |
| animations: { | |
| self.alpha = 1 | |
| } | |
| ) | |
| } else { | |
| self.alpha = 1 | |
| } | |
| } | |
| func hide(animated: Bool) { | |
| if animated { | |
| UIView.animate( | |
| withDuration: animationDuration, | |
| animations: { | |
| self.alpha = 0 | |
| }, | |
| completion: { _ in | |
| self.isHidden = true | |
| } | |
| ) | |
| } else { | |
| self.alpha = 0 | |
| self.isHidden = true | |
| } | |
| } | |
| } | |
| fileprivate var animationDuration: TimeInterval = 0.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment