Unable to change UIInputView height

前端 未结 4 2055
北荒
北荒 2021-02-14 08:55

I have a simple UIInputViewController subclass with only two overridden methods. I use this input view controller as inputAccessoryViewController on my UIViewContro

相关标签:
4条回答
  • 2021-02-14 09:29

    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!

    0 讨论(0)
  • 2021-02-14 09:42

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

    0 讨论(0)
  • 2021-02-14 09:44

    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.

    0 讨论(0)
  • 2021-02-14 09:55

    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)
    }
    
    0 讨论(0)
提交回复
热议问题