Commit a85bc54e authored by Steven杜宇's avatar Steven杜宇

AI

parent d38b6122
...@@ -33,7 +33,7 @@ class YHAutoTextView: UITextView, UITextViewDelegate { ...@@ -33,7 +33,7 @@ class YHAutoTextView: UITextView, UITextViewDelegate {
override init(frame: CGRect, textContainer: NSTextContainer?) { override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer) super.init(frame: frame, textContainer: textContainer)
delegate = self // delegate = self
isScrollEnabled = false // 禁止滚动 isScrollEnabled = false // 禁止滚动
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
clearsOnInsertion = true clearsOnInsertion = true
...@@ -51,12 +51,12 @@ class YHAutoTextView: UITextView, UITextViewDelegate { ...@@ -51,12 +51,12 @@ class YHAutoTextView: UITextView, UITextViewDelegate {
} }
// UITextViewDelegate 方法 // UITextViewDelegate 方法
func textViewDidChange(_ textView: UITextView) { // func textViewDidChange(_ textView: UITextView) {
// 更新自身的高度 // // 更新自身的高度
invalidateIntrinsicContentSize() // invalidateIntrinsicContentSize()
placeholderLabel.isHidden = !textView.text.isEmpty // placeholderLabel.isHidden = !textView.text.isEmpty
text = textView.text // text = textView.text
} // }
override var intrinsicContentSize: CGSize { override var intrinsicContentSize: CGSize {
// 计算内容的尺寸 // 计算内容的尺寸
......
...@@ -55,16 +55,15 @@ class YHAIViewController: YHBaseViewController { ...@@ -55,16 +55,15 @@ class YHAIViewController: YHBaseViewController {
gk_navTitle = "AI对话" gk_navTitle = "AI对话"
self.view.addSubview(self.tableView) self.view.addSubview(self.tableView)
self.view.addSubview(self.bottomInputView) self.view.addSubview(self.bottomInputView)
bottomInputView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
}
tableView.snp.makeConstraints { make in tableView.snp.makeConstraints { make in
make.left.right.equalTo(0) make.left.right.equalTo(0)
make.top.equalTo(k_Height_NavigationtBarAndStatuBar) make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
make.bottom.equalTo(bottomInputView.snp.top).offset(-10) make.bottom.equalTo(bottomInputView.snp.top).offset(-10)
} }
bottomInputView.addKeyBoardNotify() bottomInputView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
}
} }
......
...@@ -12,8 +12,7 @@ import IQKeyboardManagerSwift ...@@ -12,8 +12,7 @@ import IQKeyboardManagerSwift
class YHAITextInputView: UIView { class YHAITextInputView: UIView {
var sendBlock: ((String)->())? var sendBlock: ((String)->())?
static let height = 72.0
lazy var contentView: UIView = { lazy var contentView: UIView = {
let v = UIView() let v = UIView()
v.backgroundColor = .white v.backgroundColor = .white
...@@ -44,6 +43,7 @@ class YHAITextInputView: UIView { ...@@ -44,6 +43,7 @@ class YHAITextInputView: UIView {
var textView: YHAutoTextView = { var textView: YHAutoTextView = {
let v = YHAutoTextView(frame: .zero) let v = YHAutoTextView(frame: .zero)
v.font = .PFSC_R(ofSize: 14)
return v return v
}() }()
...@@ -61,7 +61,6 @@ class YHAITextInputView: UIView { ...@@ -61,7 +61,6 @@ class YHAITextInputView: UIView {
} }
func addKeyBoardNotify() { func addKeyBoardNotify() {
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
} }
...@@ -72,7 +71,6 @@ class YHAITextInputView: UIView { ...@@ -72,7 +71,6 @@ class YHAITextInputView: UIView {
func createUI() { func createUI() {
self.addSubview(whiteView) self.addSubview(whiteView)
whiteView.addSubview(contentView) whiteView.addSubview(contentView)
contentView.addSubview(sendBtn) contentView.addSubview(sendBtn)
...@@ -85,7 +83,7 @@ class YHAITextInputView: UIView { ...@@ -85,7 +83,7 @@ class YHAITextInputView: UIView {
contentView.snp.makeConstraints { make in contentView.snp.makeConstraints { make in
make.left.equalTo(20) make.left.equalTo(20)
make.top.equalTo(10) make.top.equalTo(10)
make.bottom.equalTo(-20) make.bottom.equalTo(-10)
make.right.equalTo(-20) make.right.equalTo(-20)
} }
...@@ -102,30 +100,25 @@ class YHAITextInputView: UIView { ...@@ -102,30 +100,25 @@ class YHAITextInputView: UIView {
make.bottom.equalTo(-16) make.bottom.equalTo(-16)
make.right.equalTo(sendBtn.snp.left).offset(-10) make.right.equalTo(sendBtn.snp.left).offset(-10)
} }
addKeyBoardNotify()
} }
@objc func handleKeyboardNotification(_ notification: Notification) { @objc func handleKeyboardNotification(_ notification: Notification) {
if notification.userInfo != nil { if notification.userInfo != nil {
guard let keyboardFrame = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue else {return } guard let keyboardFrame = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue else {return }
let isKeyboardShow = notification.name == UIResponder.keyboardWillShowNotification let isKeyboardShow = notification.name == UIResponder.keyboardWillShowNotification
let bottomMargin = (isKeyboardShow ? -keyboardFrame.height : 0) let bottomMargin = (isKeyboardShow ? -keyboardFrame.height : 0)
if !isKeyboardShow {
IQKeyboardManager.shared.enable = true
}
self.snp.updateConstraints { make in self.snp.updateConstraints { make in
make.bottom.equalToSuperview().offset(bottomMargin) make.bottom.equalToSuperview().offset(bottomMargin)
} }
self.setNeedsLayout() self.setNeedsLayout()
self.layoutIfNeeded() self.layoutIfNeeded()
if !isKeyboardShow {
// self.dismiss()
}
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment