带有表情符号设置的UITextView.text:cursorPosition不正确
这里, str
包含emojis,并且设置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)