ルートビューコントローラー内で、次のように子ビューコントローラーのビューをサブビューとして追加しています。
ChildViewController *cvc = [[ChildViewController alloc] init];
[self addChildViewController:cvc];
[self.view addSubview:cvc.view];
[cvc didMoveToParentViewController:self];
そして、NSLayoutConstraintを使用して、cvc.viewを親ビュー(self.view)内に配置し、cvc.viewが親ビューの下部から25ポイント上に配置されるようにします。私の理解では、次のことが機能するはずです。
UIView *superview = self.view;
UIView *childview = cvc.view;
NSLayoutConstraint *cn =
[NSLayoutConstraint withItem:childview
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:superview attribute:NSLayoutAttributeBottom
multiplier: 1.0
constant: -25.0];
[superview addConstraint: cn];
ただし、実行時に制約は失敗します。最初は、子ビューの自動サイズ変更マスクが問題を引き起こしている可能性があると思ったので(そして自動レイアウトに関するWWDC 2012イントロビデオに従って)、設定しましたが、子ビューが表示され[childview setTranslatesAutoresizingMaskIntoConstraints:NO]
ません。
私は何が間違っているのですか?