When will (or won't) updateViewConstraints be called on my view controller for me by the framework?

topwik picture topwik · Jul 5, 2013 · Viewed 18.3k times · Source

I have a view controller and I want to craete and set my view constraints in updateViewConstraints. I have a break point in that method and it's never getting called.

Why might it not be getting called? When will the framework want to call this method on my view controller?

Answer

lxt picture lxt · Jul 5, 2013

updateViewConstraints is called by viewWillLayoutSubviews (via your view's layoutSubviews method along the way). As the name suggests, this is called whenever your view controller needs to update its layout.

If you finding that updateViewConstraints is never being called then you should make sure that you are calling super your view controller's methods where required.

Also, it sounds as if you are creating your constraints inside updateViewConstraints? That may also be the cause of your problem. You should be updating your constraints in that method, not creating them (in the same way that in layoutSubviews you position your views, but don't instantiate them).