微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决附件视图中的未知高度限制

我正在尝试创建一个 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="=">”来自哪里。

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

解决方法

在评论中查看的回答。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。