Skip to content

Instantly share code, notes, and snippets.

@BradB132
Created May 28, 2015 22:20
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 BradB132/10f51b313530bac275ec to your computer and use it in GitHub Desktop.
Save BradB132/10f51b313530bac275ec to your computer and use it in GitHub Desktop.
AutoLayoutRecipesPt1-1
@IBOutlet weak var constraint1: NSLayoutConstraint!
@IBOutlet weak var constraint2: NSLayoutConstraint!
@IBAction func animateViews(sender: AnyObject) {
constraint1.constant = CGFloat(arc4random_uniform(200))
constraint2.constant = CGFloat(arc4random_uniform(200))
UIView.animateWithDuration(0.5, animations: {
self.view.setNeedsUpdateConstraints()
self.view.layoutIfNeeded()
})
}
@chrisortman
Copy link

@BradB132 I'm reading through your autolayout blog posts (they are extremely helpful, thank you!) and I don't understand why in some of your action outlets you are able to change the constraint.constant value and the UI will update accordingly but in this example you call setNeedsUpdateConstraints and layoutIfNeeded

Why doesn't the UI update immediately after executing line 5 and again after executing line 6 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment