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

// AI

parent 25820cf8
...@@ -17,6 +17,7 @@ class YHAutoTextView: UITextView, UITextViewDelegate { ...@@ -17,6 +17,7 @@ class YHAutoTextView: UITextView, UITextViewDelegate {
} }
} }
let maxHeight = 105.0
var placeHolder: String = "" { var placeHolder: String = "" {
didSet { didSet {
placeholderLabel.text = placeHolder placeholderLabel.text = placeHolder
...@@ -55,17 +56,24 @@ class YHAutoTextView: UITextView, UITextViewDelegate { ...@@ -55,17 +56,24 @@ class YHAutoTextView: UITextView, UITextViewDelegate {
placeholderLabel.isHidden = !textView.text.isEmpty placeholderLabel.isHidden = !textView.text.isEmpty
text = textView.text text = textView.text
} }
override var intrinsicContentSize: CGSize { override var intrinsicContentSize: CGSize {
// 计算内容的尺寸 // 计算内容的尺寸
// var height = self.getHeight(text: self.text, font: self.font!, width: frame.width) // var height = self.getHeight(text: self.text, font: self.font!, width: frame.width)
// if height < 20.0 { // if height < 20.0 {
// height = 20.0 // height = 20.0
// } // }
// // 加上textView周边的缝隙 // // 加上textView周边的缝隙
// height += 15.0 // height += 15.0
let size = sizeThatFits(CGSize(width: frame.width, height: .greatestFiniteMagnitude)) let size = sizeThatFits(CGSize(width: frame.width, height: .greatestFiniteMagnitude))
return CGSize(width: size.width, height: size.height) var height = size.height
isScrollEnabled = height > maxHeight
if height > maxHeight {
height = maxHeight
}
return CGSize(width: size.width, height: height)
} }
func getHeight(text:String, font:UIFont, width:CGFloat)->CGFloat { func getHeight(text:String, font:UIFont, width:CGFloat)->CGFloat {
......
...@@ -84,7 +84,7 @@ class YHAITextInputView: UIView { ...@@ -84,7 +84,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(-10) make.bottom.equalTo(-10-k_Height_safeAreaInsetsBottom())
make.right.equalTo(-20) make.right.equalTo(-20)
} }
...@@ -113,6 +113,10 @@ class YHAITextInputView: UIView { ...@@ -113,6 +113,10 @@ class YHAITextInputView: UIView {
let isKeyboardShow = notification.name == UIResponder.keyboardWillShowNotification let isKeyboardShow = notification.name == UIResponder.keyboardWillShowNotification
let bottomMargin = (isKeyboardShow ? -keyboardFrame.height : 0) let bottomMargin = (isKeyboardShow ? -keyboardFrame.height : 0)
contentView.snp.updateConstraints { make in
make.bottom.equalTo(-10-(isKeyboardShow ? 0.0 : k_Height_safeAreaInsetsBottom()))
}
self.snp.updateConstraints { make in self.snp.updateConstraints { make in
make.bottom.equalTo(bottomMargin) make.bottom.equalTo(bottomMargin)
} }
......
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