Skip to content

Instantly share code, notes, and snippets.

@srstanic
Last active November 22, 2017 10:53
Show Gist options
  • Select an option

  • Save srstanic/092685863c0ba3882778df5775264bfa to your computer and use it in GitHub Desktop.

Select an option

Save srstanic/092685863c0ba3882778df5775264bfa to your computer and use it in GitHub Desktop.
Showing and hiding UIView
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