Commit 9819c93f authored by Steven杜宇's avatar Steven杜宇

// AI

parent ff737973
...@@ -10,14 +10,18 @@ import UIKit ...@@ -10,14 +10,18 @@ import UIKit
class YHAutoTextView: UITextView, UITextViewDelegate { class YHAutoTextView: UITextView, UITextViewDelegate {
var textChange:((String)->())?
override open var text: String! { override open var text: String! {
didSet { didSet {
textViewDidChange(self)
self.setNeedsLayout() self.setNeedsLayout()
self.layoutIfNeeded() self.layoutIfNeeded()
} }
} }
let maxHeight = 105.0 let maxHeight = 60.0
static let verticalGap = 5.0
var placeHolder: String = "" { var placeHolder: String = "" {
didSet { didSet {
placeholderLabel.text = placeHolder placeholderLabel.text = placeHolder
...@@ -54,7 +58,7 @@ class YHAutoTextView: UITextView, UITextViewDelegate { ...@@ -54,7 +58,7 @@ class YHAutoTextView: UITextView, UITextViewDelegate {
// 更新自身的高度 // 更新自身的高度
invalidateIntrinsicContentSize() invalidateIntrinsicContentSize()
placeholderLabel.isHidden = !textView.text.isEmpty placeholderLabel.isHidden = !textView.text.isEmpty
text = textView.text textChange?(textView.text)
} }
override var intrinsicContentSize: CGSize { override var intrinsicContentSize: CGSize {
...@@ -72,6 +76,15 @@ class YHAutoTextView: UITextView, UITextViewDelegate { ...@@ -72,6 +76,15 @@ class YHAutoTextView: UITextView, UITextViewDelegate {
isScrollEnabled = height > maxHeight isScrollEnabled = height > maxHeight
if height > maxHeight { if height > maxHeight {
height = maxHeight height = maxHeight
self.snp.updateConstraints { make in
make.top.equalTo(11)
make.bottom.equalTo(-11)
}
} else {
self.snp.updateConstraints { make in
make.top.equalTo(11-Self.verticalGap)
make.bottom.equalTo(-(11-Self.verticalGap))
}
} }
return CGSize(width: size.width, height: height) return CGSize(width: size.width, height: height)
} }
......
...@@ -68,7 +68,6 @@ class YHAIViewController: YHBaseViewController { ...@@ -68,7 +68,6 @@ class YHAIViewController: YHBaseViewController {
bottomInputView.snp.makeConstraints { make in bottomInputView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview() make.left.right.bottom.equalToSuperview()
} }
} }
func handleMessage(_ res: YHAIResponse) { func handleMessage(_ res: YHAIResponse) {
......
...@@ -31,20 +31,32 @@ class YHAITextInputView: UIView { ...@@ -31,20 +31,32 @@ class YHAITextInputView: UIView {
lazy var sendBtn: UIButton = { lazy var sendBtn: UIButton = {
let btn = UIButton(type: .custom) let btn = UIButton(type: .custom)
btn.backgroundColor = .red btn.setImage(UIImage(named: "ai_chat_send"), for: .normal)
btn.addTarget(self, action: #selector(didSendButtonClicked), for: .touchUpInside) btn.addTarget(self, action: #selector(didSendButtonClicked), for: .touchUpInside)
btn.YH_clickEdgeInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20) btn.YH_clickEdgeInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
btn.alpha = 0.3
btn.isEnabled = false
return btn return btn
}() }()
@objc func didSendButtonClicked() { @objc func didSendButtonClicked() {
sendBlock?(textView.text) sendBlock?(textView.text)
textView.text = "" textView.text = ""
textView.isScrollEnabled = false
sendBtn.alpha = 0.3
sendBtn.isEnabled = false
self.endEditing(true)
} }
var textView: YHAutoTextView = { lazy var textView: YHAutoTextView = {
let v = YHAutoTextView() let v = YHAutoTextView()
v.font = .PFSC_R(ofSize: 14) v.font = .PFSC_R(ofSize: 14)
v.textChange = {
[weak self] text in
guard let self = self else { return }
sendBtn.alpha = text.count > 0 ? 1.0 : 0.3
sendBtn.isEnabled = text.count > 0
}
return v return v
}() }()
...@@ -97,8 +109,8 @@ class YHAITextInputView: UIView { ...@@ -97,8 +109,8 @@ class YHAITextInputView: UIView {
textView.snp.makeConstraints { make in textView.snp.makeConstraints { make in
make.left.equalTo(5) make.left.equalTo(5)
make.top.equalTo(4) make.top.equalTo(11-YHAutoTextView.verticalGap)
make.bottom.equalTo(-4) make.bottom.equalTo(-(11-YHAutoTextView.verticalGap))
make.right.equalTo(sendBtn.snp.left).offset(-5) make.right.equalTo(sendBtn.snp.left).offset(-5)
} }
addKeyBoardNotify() addKeyBoardNotify()
......
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Frame.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Frame-1.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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