此处,str
包含表情符号且设置的 cursorPosition 不正确:
let cursorPosition = str.characters.count
let cursorRange = NSRange(location: cursorPosition, length: 0)
textInputView.selectedRange = cursorRange
textInputView.scrollRangeToVisible(cursorRange)
最佳答案
看起来您想将光标放在 textView
的最后。像这样尝试。
textInputView.becomeFirstResponder()
let cursorPosition = str.utf16.count
let cursorRange = NSRange(location: cursorPosition, length: 0)
textInputView.selectedRange = cursorRange
textInputView.scrollRangeToVisible(cursorRange)
关于ios - 带有表情符号设置 : cursorPosition is not correct 的 UITextView.text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43247038/