Unable to change UIInputView height

a 夏天 提交于 2019-12-03 12:02:09

Since iOS 9.0 this can be solved with inputView.allowsSelfSizing = YES;

I don't know if this is the issue, but the problem may come from the 0.0 multiplier you are setting on _heightConstraint. Try to change it to 1.0.

It would look like this:

NSLayoutConstraint *_heightConstraint = 
    [NSLayoutConstraint constraintWithItem:self.view
                                 attribute:NSLayoutAttributeHeight
                                 relatedBy:NSLayoutRelationEqual
                                    toItem:nil
                                 attribute:NSLayoutAttributeNotAnAttribute
                                 multiplier:1.0
                                   constant: _expandedHeight];

Hope this helps!

moger777

When you make a view the input accessory view of a UITextView, as soon as the text view becomes first responder, a height constraint is added automatically set to whatever was sent as the frame height. For example:

let inputView = UIInputView(frame: CGRectMake(0, 0, view.bounds.width, 200), 
    inputViewStyle: .Default)
someTextView.inputAccessoryView = inputView
someTextView.becomeFirstResponder()
assert((inputView.constraints().last as NSLayoutConstraint).constant == 200)

You can modify this constraint after the fact.

I did it in Swift. hope this helps you.

override func viewDidAppear(animated: Bool) {

    let heightConstraint = NSLayoutConstraint(
        item:self.view,
        attribute:NSLayoutAttribute.Height,
        relatedBy:NSLayoutRelation.Equal,
        toItem:nil,
        attribute:NSLayoutAttribute.NotAnAttribute,
        multiplier:0.0,
        constant:100)

    self.view.addConstraint(heightConstraint)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!