Created
May 19, 2020 14:55
-
-
Save stevencurtis/28d83161ff4506d4912b3807e8ac052c to your computer and use it in GitHub Desktop.
setupConstraintsViewAndAnimate
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
func setupConstraintsViewAndAnimate() { | |
constraintsView.backgroundColor = .purple | |
self.view.addSubview(constraintsView) | |
constraintsView.translatesAutoresizingMaskIntoConstraints = false | |
var topConstraint = constraintsView.topAnchor.constraint(equalTo: self.view.topAnchor) | |
let widthConstraint = constraintsView.widthAnchor.constraint(equalToConstant: 200) | |
let heightConstraint = constraintsView.heightAnchor.constraint(equalToConstant: 200) | |
NSLayoutConstraint.activate([ | |
topConstraint, | |
widthConstraint, | |
heightConstraint | |
]) | |
NSLayoutConstraint.deactivate([ | |
topConstraint | |
]) | |
let newConstraint = constraintsView.topAnchor.constraint( | |
equalTo: self.view.topAnchor, | |
constant: 400) | |
NSLayoutConstraint.activate([ | |
newConstraint | |
]) | |
UIView.animate(withDuration: 0.5) { | |
topConstraint = newConstraint | |
self.view.layoutIfNeeded() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment