Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

enter image description here

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.

like image 432
an0 Avatar asked Oct 01 '12 14:10

an0


1 Answers

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.
}
like image 99
an0 Avatar answered Sep 27 '22 18:09

an0