Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 216
topwik Avatar asked Jul 05 '13 21:07

topwik


2 Answers

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).

like image 109
lxt Avatar answered Oct 22 '22 13:10

lxt


You are in ViewController and you want the system to call updateViewConstraints, then you have to call this

[self.view setNeedsUpdateConstraints];
like image 15
onmyway133 Avatar answered Oct 22 '22 14:10

onmyway133