MessageKit:添加的输入栏按钮仅在我发送消息后出现

问题描述

我正在使用 MessageKit 构建应用。

我在输入栏中添加了一个 InputBarItem,但是当视图第一次出现时它没有出现。只有在我按下“发送”后,项目才会出现。

下面是 ChatViewController 的一部分。知道为什么会发生这种情况吗?

谢谢!

class ChatViewController: MessagesViewController {
    
    ....

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
       ...
        
        messageInputBar.delegate = self
    
        setupConstraints()
    }

}

extension ChatViewController: MessagesDataSource {
    ...
}


// MARK: - MessageInputBarDelegate

extension ChatViewController: InputBarAccessoryViewDelegate {

    @objc
    func inputBar(_ inputBar: InputBarAccessoryView,didPressSendButtonWith text: String) {
        processInputBar(messageInputBar)
    }

    private func makeButton(named: String) -> InputBarButtonItem {
        return InputBarButtonItem()
            .configure {
                $0.spacing = .fixed(10)
                $0.image = UIImage(systemName: named)?.withRenderingMode(.alwaysTemplate)
                $0.setSize(CGSize(width: 25,height: 25),animated: false)
                $0.tintColor = .blue
            }
    }
    
    func processInputBar(_ inputBar: InputBarAccessoryView) {
        let components = inputBar.inputTextView.components
        
        inputBar.inputTextView.text = String()
        let items = [
            makeButton(named: "plus")
        ]
        inputBar.setLeftStackViewWidthConstant(to: 36,animated: false)
        inputBar.setStackViewItems(items,forStack: .left,animated: false)
    }
}


解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)