Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created May 19, 2020 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencurtis/28d83161ff4506d4912b3807e8ac052c to your computer and use it in GitHub Desktop.
Save stevencurtis/28d83161ff4506d4912b3807e8ac052c to your computer and use it in GitHub Desktop.
setupConstraintsViewAndAnimate
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