在这里,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 - 带有表情符号设置的UITextView.text:cursorPosition不正确,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43247038/