Menu & Search

Animating Auto Layout Constraints

September 16, 2015

A frequent question amongst iOS developers is how to animate Auto Layout constraint changes. Previously, we’ve been adjusting and setting the frame inside the animation block of the UIView.animateWith… method. Now, all we have to do is:

  1. Adjust the constraints
  2. Call view.setNeedsLayout() (sometimes, not always necessary)
  3. Call view.layoutIfNeeded()
  4. Write the animation code like you’d usually do but only call view.layoutIfNeeded().

Example

That’s it! Happy animation!

STOP LOSING TIME WITH AUTO LAYOUT!

Take part in the 5-day course with actionable tasks that will let you become a master at recognizing and solving the most common mistakes iOS developers do with Auto Layout.

Let Auto Layout become a tool you swing with your utmost confidence!

I won't send you spam, I promise. Unsubscribe at any time. Powered by ConvertKit
Hey there! You're already subscribed to my newsletter and you've hopefully gotten some useful tips and tricks when working with iOS. If you're also working with Auto Layout, make sure to check out my book called Auto Layout Fundamentals and get a 20% off for being my subscriber! https://gum.co/autolayoutfundamentals/youareawesome
Jure Zove

A lot of things but mostly a programmer who really likes fast cars. Check me out on Twitter, if you fancy.

Related article

Introducing The “How do I Auto Layout” Cheatsheet

STOP LOSING TIME WITH AUTO LAYOUT! Take part in the…

Fastest way to use Auto Layout in code

Raise your ✋ if you hate adding views and setting…

Swift Optionals Demystified

STOP LOSING TIME WITH AUTO LAYOUT! Take part in the…

Type your search keyword, and press enter to search