Skip to content

Instantly share code, notes, and snippets.

@interealtime
Last active August 29, 2015 14:04
Show Gist options
  • Save interealtime/c24436a16885166af4de to your computer and use it in GitHub Desktop.
Save interealtime/c24436a16885166af4de to your computer and use it in GitHub Desktop.
Autolayout: modifying constraint multipliers / replacing IB constraints in code
If you set a constraint in Interface Builder and replace it in code for whatever reason (in my case I needed to change the multiplier to animate an aspect ratio), beware.
What happens: You replace that constraint, it works fine. Then the view rotates, and the hierarchy is re-computed. That constraint that you deleted and replaced in code? It gets added back. Now you have 2 conflicting constraints. Bad things happen.
What you should do: Delete that constraint in Interface Builder (or mark it as a placeholder / remove at build time), and create it from code when the view loads.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment