DevPrep

All topics › UIKit

How do you animate Auto Layout constraint changes?

Middle PRO

The gist

The constraint itself is not animated. What animates is the result of the layout pass: you change constant / isActive / priority and then call layoutIfNeeded() inside the animation block. Core Animation interpolates the frames from the old values to the new ones.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store