无法更改UIInputView高度

hyb*_*ttt 10 objective-c ios autolayout ios8 uiinputviewcontroller

我有一个简单的UIInputViewController子类,只有两个重写的方法.我inputAccessoryViewController在我的UIViewController子类上使用此输入视图控制器,它成为第一响应者.我尝试通过添加约束来指定inputView的高度,如Apple文档所建议的那样.问题是我的约束不起作用,并且在添加约束时我得到autolayout异常

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)]>
Run Code Online (Sandbox Code Playgroud)

我认为这意味着系统已经为输入视图添加了零高度约束(因为它创建的高度为零).现在他们冲突和自动布局打破我的约束来解决问题.

当我尝试使用它作为inputViewController我的视图控制器(仅用于测试目的)时,我得到相同的异常,但不是零高度,它是216 px.它也打破了我的约束,高度保持默认.

- (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];
}
Run Code Online (Sandbox Code Playgroud)

因此,我无法更改输入附件视图高度.有没有人成功呢?显然,Apple文档没有提供任何帮助......

Ben*_*air 9

从iOS 9.0开始,这可以解决 inputView.allowsSelfSizing = YES;