オーバーライドされたメソッドが 2 つだけの単純な UIInputViewController サブクラスがあります。この入力ビュー コントローラーをinputAccessoryViewController
、最初のレスポンダーになる UIViewController サブクラスと同様に使用します。Appleのドキュメントが推奨するように、制約を追加してinputViewの高さを指定しようとしています。問題は、制約が機能せず、制約が追加されているときに自動レイアウト例外が発生することです
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
...
(
"<NSLayoutConstraint:0x178aa1d0 V:[UIInputView:0x178a4ae0(0)]>",
"<NSLayoutConstraint:0x178b9520 V:[UIInputView:0x178a4ae0(500)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x178b9520 V:[UIInputView:0x178a4ae0(500)]>
これは、システムがすでに高さゼロの制約を入力ビューに追加していることを意味すると思います (高さがゼロで作成されているため)。現在、それらは競合し、自動レイアウトは私の制約を破って問題を解決しています。
ビューコントローラーとして(テスト目的で)使用しようとすると、inputViewController
同じ例外が発生しますが、高さがゼロではなく216ピクセルです。それは私の制約にも違反し、高さはデフォルトのままです。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.inputView.translatesAutoresizingMaskIntoConstraints = NO;
self.inputView.backgroundColor = [UIColor redColor];
}
- (void)updateViewConstraints {
CGFloat _expandedHeight = 500;
NSLayoutConstraint *_heightConstraint =
[NSLayoutConstraint constraintWithItem:self.view
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:0.0
constant: _expandedHeight];
[self.inputView addConstraint: _heightConstraint];
[super updateViewConstraints];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.view setNeedsUpdateConstraints];
}
その結果、入力アクセサリ ビューの高さを変更できません。それに成功した人はいますか?明らかに、Apple のドキュメントには何の助けもありません...