當(dāng)我們做自適應(yīng)textview高度時(shí),當(dāng)輸入文本時(shí),textview會(huì)向上偏移一段距離
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
var resultText: String = ""
if text == "" {
if textView.text == "" {
resultText = textView.text
} else {
resultText = String(textView.text.prefix(textView.text.count - 1))
}
} else {
resultText = textView.text + text
}
return true
}
當(dāng)我們用上邊的方式去獲取當(dāng)前的文本,然后根據(jù)文本去計(jì)算textview的高度時(shí),就不會(huì)有偏移的問(wèn)題