【发布时间】:2021-06-16 03:01:06
【问题描述】:
我想在用户输入时将图像附件添加到 UITextview,这很好,但问题是 CPU 增长与添加的图像附件数量一样多。 90%。并导致 UI 滞后等缓慢。我已将图像调整为小尺寸,但问题仍然存在。 here is image what I'm doing
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
for data in arrDataModel {
if data.textDefaul == text {
let attachment = NSTextAttachment()
if let image = data.imageData {
let imageNew = UIImage(data: image)!
attachment.image = imageNew
let attString = NSAttributedString(attachment: attachment)
txtViewShow.textStorage.replaceCharacters(in: range, with: attString)
}
break
}
}
return true
}
【问题讨论】:
-
每当添加新附件时,它似乎 uitextview 都会重绘所有附件。但我不知道如何避免它
标签: ios swift performance text uitextview