IOS keyboard pen

According to the document ,

Marked text, which is part of multi-step text input, represents pre-inserted text that the user has not yet confirmed. It is stylized in distinctive form. The range of the marked text always contains within it the range of the selected text, which can be characters or carriages.

And in the chapter Managing the keyboard . Figure 5-2 shows the text that says:

enter image description here

Given the 4th and 6th images, the top panel on the keyboard represents the marked text, for example, “修”, “修改”, “修身”, etc.

What I'm confused with is the HOWTO:

  • Detect user on selected text. This will replace the selected text or just pasted the selected text.
  • Show custom text in the panel. For example, [textView showMarkedText:@"hello" atIndex:0] .

Thanks.

+6
source share
1 answer

Actually, you are a little confused with the "marked text" and the "candidate text".

Take a Chinese handwriting keyboard, for example, the symbol “修” lies on a note called “marked text,” which has a distinctive style. And “修”, “修改”, “修身”, ... on the keyboard, you can call them “candidates” (the panel in which they were placed is called the “candidate panel” if you check the hierarchy of keyboard representations).

There are some interfaces for working with marked text. You can take a look at the UITextInput protocol, which is confirmed by UITextView and UITextField . -setMarkedText:selectedRange: and -unmarkText will make it difficult.

There is no public API for working on the candidates panel, and how to detect a crane on it is also not documented. But you can indirectly detect this by doing -textView:shouldChangeTextInRange:replacementText: and -textViewDidChange: in the UITextViewDelegate protocol if you use UITextView (or the partner methods for UITextField if you use it).

PS: There is, at least, as I know, an exception for the Chinese keyboard, which seems like an error. When you click on the candidates panel on the Chinese keyboard, the text you use applies to your UITextView (or UITextField ) without -textView:shouldChangeTextInRange:replacementText: But -textViewDidChange: will be called in the end.

Hope this helps.

+2
source

All Articles