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