Skip to content

Instantly share code, notes, and snippets.

@OksanaFedorchuk
Created April 21, 2021 14:13
Show Gist options
  • Save OksanaFedorchuk/9e2e17de3f31a87eb6ad223b832e7c55 to your computer and use it in GitHub Desktop.
Save OksanaFedorchuk/9e2e17de3f31a87eb6ad223b832e7c55 to your computer and use it in GitHub Desktop.
Extension for UIView, to make pop up animation
extension UIView {
//adding subview to a view, animated
func animateIn(view: UIView) {
self.backgroundColor = .clear
self.addSubview(view)
view.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
view.alpha = 0
UIView.animate(withDuration: 0.3) {
view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
view.alpha = 1
}
}
//removing subview from a view, animated
func animateOut(view: UIView) {
UIView.animate(withDuration: 0.3, animations: {
view.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
view.alpha = 0
}) { _ in
view.removeFromSuperview()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment