When using Auto Layout, it will be inevitable that you would also want to animate views where constraints are used. Here’s a guide on how to animate Auto Layout constraints in iOS.

First, get a reference to the layout constraint. You can do this in the storyboard, by assigning an IBOutlet property to a constraint. (Select the constraint, hold control, then drag to your .m file).

Next, on your method which will trigger the animation, update the constraints. For example:

If other constraints will be affected because of the update to the constraint above, the following must also be called:

Now, animate yout view by calling “layoutIfNeeded” inside your animation block.
Note that you should call the “layoutIfNeeded” method of your parent container view, not the view that will be animated. If you do otherwise, then the animation will not take effect, only the constraint will (which results to immediate update of your view’s frame).

The “self.view” above is the main view of my UIViewController.

Done! Your view should now animate.





Happy Goals for iOS

Happy Goals for iOS

Want an app to help you track and achieve your goals, without the complex stuff, saving you from headaches? Checkout Happy Goals - Habits & Goals Tracker now in the App Store! Happy Goals has been featured in the App Store in over 32 countries. Start now, better late than never!


Thank you!

%d bloggers like this: