Created
April 21, 2021 14:13
-
-
Save OksanaFedorchuk/9e2e17de3f31a87eb6ad223b832e7c55 to your computer and use it in GitHub Desktop.
Extension for UIView, to make pop up animation
This file contains 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 { | |
//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