当我粘贴UITextView
中的文本时,会添加一些额外的空间。但是当我滚动它时,textView
根据内容拟合。在textViewDidChange
中,textView
高度约束根据其内容大小进行设置。有人遇到同样的问题吗?
func textViewDidChange(_ textView: UITextView) {
let newSize = textView.sizeThatFits(CGSize.init(width: textView.frame.size.width, height: CGFloat(MAXFLOAT)))
textView.isScrollEnabled = false
if newSize.height < 37 {
self.messageTextViewHeightConstraint.constant = minimumTextviewHeight
}
if (newSize.height >= 37 && newSize.height <= 100) {
self.messageTextViewHeightConstraint.constant = newSize.height
}
if (newSize.height >= 100) {
self.messageTextViewHeightConstraint.constant = maximumTextviewHeight
self.textView.isScrollEnabled = true
}
}
答案 0 :(得分:2)
您必须将textView的smartInsertDeleteType设置为.no
textView.smartInsertDeleteType = .no
参考链接:https://developer.apple.com/documentation/uikit/uitextinputtraits/2865828-smartinsertdeletetype