iosswiftinputaccessoryview

Unknown height constraint in accessory view


I am trying to create a chatView as an input accessory view for my iOS app. In this chatView, there are some buttons and a UITextView. When this textView goes to the next line, I want to change the size of this chatView. However, there is a mysterious constraint named "accessory" that is created from the frame. But I don't know where to find this constraint.

This is a code snippet from chatView:

lazy var chatBoxView: UIView = {
        let chatBoxView = UIView(frame: CGRect(x: 0, y: 0, width: 375, height: 85))
        chatBoxView.translatesAutoresizingMaskIntoConstraints = false
        let heightConstraint = chatBoxView.heightAnchor.constraint(equalToConstant: 120)
        heightConstraint.isActive = true
...
}

So here, Im setting the frame of the UIView. Then, I'm trying to set a height constraint (This is just to test that there is a conflict in constraints).

And I set the chatBoxView as the inputAccessoryView.

 override var inputAccessoryView: UIView? {
        get {
            return chatBoxView
        }
    }
    
    override var canBecomeFirstResponder: Bool {
        return true
    }
    

The error message that I'm getting is:

[LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x60000014d630 UIView:0x7fc7b6c840a0.height == 120   (active)>",
    "<NSLayoutConstraint:0x60000014df90 'accessoryHeight' UIView:0x7fc7b6c840a0.height == 85   (active)>"
)

I do not know where "<NSLayoutConstraint:0x60000014df90 'accessoryHeight' UIView:0x7fc7b6c840a0.height == 85 (active)>" is coming from.

What I want to do is dynamically change the height of this input accessory view but I cannot because the mysterious height constraint is not letting me set the new frame and getting the view updated.


Solution

  • Check Jatin's answer in the comments.