Search code examples
iosxcodeios8uikitnslayoutconstraint

Temporarily disable/remove constraints while animating UI elements


I've nicely setup my UI inside a storyboard controller. Running the app, everything looks & works great inside the iPhone 5S simulator. More importantly, all the UI elements that have their own IBOutlet (for animation purposes) to the code behave as programmed: moving as intended when methods animate these UI elements when needed.

However, I added constraints by clicking the controller inside the storyboard --> Editor --> Resolve Auto Layout Issues --> Add Missing Constraints. After that, animations stop working because the constraints are keeping them in place.

Is there some sort of command/code to "pause/stop/remove/disable" the constraints during animation & then add them back, when animations are finished, without having to do add constraints back manually?


Solution

  • If you're using Autolayout, you should not be trying to move views by changing their frames. You should be animating changes to the constraints, instead.

    See this StackOverflow answer for hints:

    How do I animate constraint changes?