Reset Constant constant NSLayoutConstraint with its original value from storyboard

Imagine a script you posted UIView

with NSLayoutConstraint

that has different constant

sizes for several classes in your storyboard. Now you want to animate the position of this view by changing this constraint 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 this value for use in your animation code?

This way, you won't have to define the size class in code and set it programmatically with values ​​that match what was already set in the storyboard.

+3


source to share


2 answers


Plug the layout constraint into an outlet in Interface Builder. Then, when your view is loaded, cache the value constraint.constant

in the ivar. Then you can change it and reset it however you like.



+1


source


1) create an exit for your constraint

2) in the condition when you want to animate the .constant constraint constraint value for the value you want to set



3) In your animation block call view.layoutIfNeeded ()

+1


source







All Articles