我有兩個視圖控制器,父和子。自動佈局約束和子視圖控制器
所以在viewDidLoad
方法我做到以下幾點:
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
//
所以基本上什麼情況是,updateViewConstraints
其實是在self.view.frame == CGRectZero
爲我指定的呼籲ChildViewController之前父控制器限制適用,所以,完全一樣定製loadView
方法ChildViewController
。
translatesAutoresizingMaskIntoConstraints
全部設置爲NO
所有視圖。
什麼是正確的方法來設置限制在這種情況下,這樣ChildViewController
父後更新自己的約束?
兩個控制器的當前日誌是相當令人沮喪,我不明白怎麼updateViewConstraints可以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}}
您需要在實際添加約束的位置顯示代碼,否則很難說出了什麼問題。 – Maarten
@Maarten我解決了這個問題,並在下面發佈了答案,不確定這是我尋找的解決方案,它似乎是錯誤的,但它的工作原理。對不起,我不能發佈代碼,它的代碼太多了...... – Andy