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

AI

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