本文介绍了如何检测用户是否使用输入法进行中途输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户使用输入法(例如中文拼音)在UITextView中输入,则存在拼音已经在文本视图中显示但是用户仍然没有选择最终中文字符的状态。屏幕截图会更清晰:

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.

推荐答案

终于搞定了。拼音等输入法称为多段文本输入。第一阶段称为标记,第二阶段称为已提交。要确定它是否在标记阶段,应该查询 UITextInput 协议的 markedTextRange property:

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.
}

这篇关于如何检测用户是否使用输入法进行中途输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 14:41