Reputation: 55835
Imagine the scenario where you have laid out a UIView
with an NSLayoutConstraint
that has different constant
s for several of the size classes in your Storyboard. Now you want to animate the position of this view by modifying that constraint's constant
. Let's say you want to animate it from -100 to its original value that you set in the storyboard for the current size class. How can you get that value to use in the animation code?
That way you wouldn't have to detect the size class in code and set it all programmatically with the values that align with what was already set in the Storyboard.
Upvotes: 3
Views: 1843
Reputation: 3475
1) create an outlet for your constraint
2) in the condition when you want to animate the constraint change constraint.constant value to the value you want to set
3) In your animation block call view.layoutIfNeeded()
Upvotes: 1
Reputation: 54620
Connect your layout constraint to an outlet in Interface Builder. Then when your view is loaded, cache the value of constraint.constant
in an ivar. Then you can change it and reset it however you wish.
Upvotes: 0