Autolayout constraints and child view controller
autolayout, objective-c
Solution
According to the following link, I moved constraints creation to `viewWillLayoutSubviews`, this is the place where view bounds are set properly. I feel this answer misses explanation on why Child view controller's updateViewConstraints called before parent view controller, or maybe it's just some bug in my code, but this workaround solves the problem...
Problem
I have two view controllers, parent and child. So in the `viewDidLoad` method I do the following: ``` ChildViewController* childViewController = [[ChildViewController alloc] init]; [self addChildViewController:childViewController]; // ChildViewController sets his own constraints in viewDidLoad [self.view addSubview:childViewController.view]; [childViewController didMoveToParentViewController:self]; // // setup constraints to expand childViewController.view to // fill the size of parent view controller // ``` So basically what happens is that `updateViewConstraints` is called on ChildViewController before parent controller constraints apply, so in fact `self.view.frame == CGRectZero`, exactly the same as I specified in custom `loadView` method in `ChildViewController`. `translatesAutoresizingMaskIntoConstraints` all set to `NO` for all views. What's the proper way to setup constraints in this case so `ChildViewController` updates his constraints after parent? Current log from both controllers is pretty frustrating, I do not understand how updateViewConstraints can be called before viewWillLayoutSubviews: ``` App[47933:c07] ChildViewController::updateViewConstraints. RECT: {{0, 0}, {0, 0}} App[47933:c07] ParentViewController::updateViewConstraints App[47933:c07] ChildViewController:viewWillLayoutSubviews. RECT: {{0, 0}, {984, 454}} App[47933:c07] ChildViewController:viewDidLayoutSubviews. RECT: {{0, 0}, {984, 454}} ```