ビューコントローラで最も近い祖先self.navigationController.navigationBar
とのサブビューはself.view
何ですか?その祖先に制約を追加できますか?
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[self.searchBar setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:self.searchBar];
NSLayoutConstraint* cn = [NSLayoutConstraint constraintWithItem:self.searchBar
attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual
toItem:self.navigationController.navigationBar attribute:NSLayoutAttributeBottom
multiplier:1.0 constant:0];
やってみた
[self.view addConstraint:cn];
[self.navigationController.view addConstraint:cn];
しかし、どちらの場合も、「制約はビューのサブツリーの外側から何かを参照していますか?それは違法です」というエラーが表示されます。
誰かがnavigationControllerに関連してViewControllerのビュー階層を説明できますか?
ありがとう!