UITextInput:selectedTextRange与markedTextRange? [英] UITextInput: selectedTextRange vs. markedTextRange?

查看:562
本文介绍了UITextInput:selectedTextRange与markedTextRange?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我知道Apple的UITextInput协议需要两个UITextRange属性selectedTextRangemarkedTextRange,并且文档说selectedTextRangemarkedTextRange的子范围,该范围是未经确认的文本范围用户yatta yatta.对于我应该如何不同地实现两个文本范围,这仍然使我不清楚.有人可以直观地向我解释selectedTextRangemarkedTextRange之间的区别吗?我知道,当selectedTextRangelength0时,它指示selectedTextRangelocation闪烁的插入符号.但是标记文本"到底是什么呢??我只在iOS的文本视图中看到过以下内容:

Ok, so I know Apple's UITextInput protocol requires the two UITextRange properties selectedTextRange and markedTextRange and the documentation says that selectedTextRange is a subrange of markedTextRange which is an uncomfirmed text range by the user yatta yatta. That still doesn't make some things clear to me regarding how I ought to implement the two text ranges differently. Could someone visually explain to me the difference between selectedTextRange and markedTextRange? I know that when the length of selectedTextRange is 0 it indicates a blinking caret at selectedTextRange's location. But what the heck is "marked text"?? I've only seen the following for text views in iOS:

我假设代表当前的selectedTextRange. markedTextRange是什么样的?还是基本上是一回事?我很困惑:(预先感谢您的帮助!在我对如何实现UITextInput协议的理解中,该文档本身无用.

Which I assume represents the current selectedTextRange. What does markedTextRange look like? Or is it basically the exact same thing? I'm so confused :( Thanks in advance for any help! The documentation has proven itself useless in my understanding of how to implement the UITextInput protocol.

编辑

实现markedTextRange是否与以下事实有关:视图中的某些文本可能是可标记的"但是只读的",而selectedTextRange表示标记的文本"中的子范围,即markedTextRange,即读写?

Does implementing markedTextRange have anything to do with the fact that some text in a view could be "markable" but "readonly" and selectedTextRange indicates the subrange in the "marked text", markedTextRange, that is readwrite?

推荐答案

摘自Apple文档中的UITextInput:

From Apple documentation for UITextInput:

标记的文本是多阶段文本输入的一部分,临时表示 用户尚未确认的已插入文本.它的风格与众不同 道路.标记文本的范围内始终包含选定的范围 文字,可能是字符范围或插入符号.

Marked text, which is part of multistage text input, represents provisionally inserted text that the user has yet to confirm. It is styled in a distinctive way. The range of marked text always contains within it a range of selected text, which might be a range of characters or the caret.

因此markedTextRange在需要多级输入的语言中很有用,例如日本人. 简而言之:markedTextRange进入游戏之前,尚未确认哪种用户类型可以添加到文本输入控件的值. GIF的波纹管演示了markedTextRange的作用:

Hence markedTextRange gets useful with languages that requires multistage input, e.g. Japanese. In simple words: what user types is yet to be confirmed before it can be added to the value of the text input control is were markedTextRange gets into the game. GIF bellow demonstrates markedTextRange in action:

请注意,未经确认的象形文字后面有轻微的蓝宝石背景.通过按Enter/Return键确认文本后,在标记的文本添加到输入控件值并删除背景后,从建议中选择选项或在文本区域上点击手指.

Notice slight sapphire background behind the unconfirmed hieroglyphs. Once text gets confirmed either by hitting enter/return, selecting option from suggestions or finger tap on text area after the marked text gets added to the input control value and background gets removed.

注释:

  • markedTextRange与只读文本无关
  • 我无法在markedTextRange中实现多个符号的选择

这篇关于UITextInput:selectedTextRange与markedTextRange?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆