我有一个简单的 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 文档没有提供任何帮助......