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

通过聊天发送图像后,InputBar仍保持展开状态

如何解决通过聊天发送图像后,InputBar仍保持展开状态

我正在使用MessageKit和inputbaraccessoryview添加聊天功能。我将其连接到Firebase,并且刚刚添加了通过聊天发送图像的功能。我面临的问题是,发送图像后,输入栏仍保持展开状态。它应将条形图重新调整为与选择图像之前相同的大小。

enter image description here

enter image description here

  class SlackInputBar: inputbaraccessoryview {

var imagesData : [Data] = []

override init(frame: CGRect) {
    super.init(frame: frame)
    configure()
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}


@objc func camerapressed(){
       let imagePicker = UIImagePickerController()
                        imagePicker.delegate = self
                        imagePicker.sourceType = .photoLibrary
                      //  (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController?.present(imagePicker,animated: true,completion: nil)
    
                        if var topController = UIApplication.shared.keyWindow?.rootViewController {
                            while let presentedViewController = topController.presentedViewController {
                                topController = presentedViewController
                            }
                            topController.present(imagePicker,animated: false,completion: nil)
                            // topController should Now be your topmost view controller
                        }
    print("camera")
}

       func configure() {
    let button = InputBarButtonItem()
    button.onKeyboardSwipeGesture { item,gesture in
        if gesture.direction == .left {
            item.inputbaraccessoryview?.setLeftStackViewWidthConstant(to: 0,animated: true)
        } else if gesture.direction == .right {
            item.inputbaraccessoryview?.setLeftStackViewWidthConstant(to: 36,animated: true)
        }
    }
    button.setSize(CGSize(width: 36,height: 36),animated: false)
 button.setimage(#imageLiteral(resourceName: "ic_plus").withRenderingMode(.alwaystemplate),for: .normal)
    button.imageView?.contentMode = .scaleAspectFit
    button.tintColor = UIColor(red: 0,green: 122/255,blue: 1,alpha: 1)
    
    button.addTarget(self,action: #selector(camerapressed),for: .touchUpInside)

    
    inputTextView.backgroundColor = UIColor(red: 245/255,green: 245/255,blue: 245/255,alpha: 1)
    inputTextView.placeholderTextColor = UIColor(red: 0.6,green: 0.6,blue: 0.6,alpha: 1)
    inputTextView.textContainerInset = UIEdgeInsets(top: 8,left: 16,bottom: 8,right: 16)
    inputTextView.placeholderLabelInsets = UIEdgeInsets(top: 8,left: 20,right: 20)
    inputTextView.layer.borderColor = UIColor(red: 200/255,green: 200/255,blue: 200/255,alpha: 1).cgColor
    inputTextView.layer.borderWidth = 1.0
    inputTextView.layer.cornerRadius = 16.0
    inputTextView.layer.masksToBounds = true
    inputTextView.scrollIndicatorInsets = UIEdgeInsets(top: 8,left: 0,right: 0)
    setLeftStackViewWidthConstant(to: 36,animated: false)
    setStackViewItems([button],forStack: .left,animated: false)
}
   func imagePickerController(_ picker: UIImagePickerController,didFinishPickingMediawithInfo info: [UIImagePickerController.InfoKey : Any]) {
 // Local variable inserted by Swift 4.2 migrator.
 let info = convertFromUIImagePickerControllerInfoKeyDictionary(info)

    
    picker.dismiss(animated: true,completion: {
        if let pickedImage = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey.originalImage)] as? UIImage {
            
            self.imagesData.append(pickedImage.pngData()!)
            self.inputPlugins.forEach { _ = $0.handleInput(of: pickedImage) }
        }
    })
}
}

  fileprivate func convertFromUIImagePickerControllerInfoKeyDictionary(_ input: [UIImagePickerController.InfoKey: Any]) -> [String: Any] {
return Dictionary(uniqueKeysWithValues: input.map {key,value in (key.rawValue,value)})
   }


  fileprivate func convertFromUIImagePickerControllerInfoKey(_ input: UIImagePickerController.InfoKey) -> String {
return input.rawValue
   }

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

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?