附件视图中的未知高度限制

问题描述

我正在尝试创建一个 chatView 作为我的 iOS 应用程序的输入附件视图。在这个 chatView 中,有一些按钮和一个 UITextView。当这个 textView 转到下一行时,我想更改这个 chatView 的大小。但是,有一个名为“附件”的神秘约束是从框架创建的。但我不知道在哪里可以找到这个约束。

这是来自 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
...
}

所以在这里,我设置了 UIView 的框架。然后,我尝试设置高度约束(这只是为了测试约束是否存在冲突)。

我将 chatBoxView 设置为 inputAccessoryView。

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

我收到的错误消息是:

[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)>"
)

我不知道“<0x60000014df90 uiview:0x7fc7b6c840a0.height="=">”来自哪里。

我想要做的是动态更改此输入附件视图的高度,但我不能,因为神秘的高度约束不允许我设置新框架并更新视图。

解决方法

在评论中查看的回答。