How to detect user is mid-way inputting with an Input Method?

泄露秘密 提交于 2019-12-03 10:20:39

问题


If user is inputting in a UITextView using an Input Method such as Chinese Pinyin, there is a state where the Pinyin is already displayed in tne text view but user is still yet to choose the final Chinese characters. A screenshot will be much more clear:

I want to do some text completion for user, but should only do it for the real input(the Chinese characters user chooses) but not for the intermediate Pinyin input. So I need to detect this pending state.


回答1:


Finally got it. Input methods like Pinyin are called Multistage Text Input. The first stage is called Marked, the second stage is called Committed. To determine whether it is in Marked stage, one should query UITextInput Protocol's markedTextRange property:

if (textView.markedTextRange != nil) {
    // Marked.
}


来源:https://stackoverflow.com/questions/12674949/how-to-detect-user-is-mid-way-inputting-with-an-input-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!