为什么Apple的SimpleTextInput示例代码效率低下
我正在查看 Apple 的 SimpleTextInput 示例代码,这是一个使用 Core Text 显示文本的 iOS 文本编辑器的示例项目。这是一件美妙的事情。
但它的自述文件说:
此示例代码不应被视为文本编辑器的模板,而应作为如何将文本输入系统绑定到预先存在的文本编辑器的示例。项目对CoreText的使用幼稚且低效;它仅处理从左到右的文本布局,对于任何文本编辑器来说它绝不是一个好的模板。它的实现只是为了说明如何将系统键盘(即文本输入系统)绑定到某些预先存在的文本编辑器。
我很好奇这个文本编辑器如何效率低下。这是其设计的基础吗?简单的调整就可以改善这一点吗? UITextView
可能隐藏着非常复杂的缓存算法;那么,问题是 SimpleTextInput 缺少它们吗?
I’m looking at Apple’s SimpleTextInput sample code, which is a sample project for an iOS text editor that uses Core Text to display the text. This is a wonderful thing.
But its ReadMe document says:
This sample code should not be considered a template for a text editor, but rather as an example of how to bind the text input system to a pre-existing text editor. The project's use of CoreText is naive and inefficient; it deals only with left-to-right text layout, and it is by no means a good template for any text editor. It is a implementation meant only to illustrate how to bind the system keyboard (that is, the text input system) to some pre-existing text editor.
I’m curious as to how this text editor is inefficient. Is it something fundamental in its design? Is it something that simple tweaks could improve? UITextView
might have really elaborate caching algorithms hidden in it; so, would the problem be that SimpleTextInput lacks them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apple 的 SimpleTextInput 示例代码,使用 Draw在单个
CTFrameRef
对象中一次性显示所有文本:这是最简单的选项,因为您可以获取核心文本以将所有内容绘制在一个块中。唯一的缺点是它的效率可能很低,因为每次击键时都重新创建CTFrameRef
并在每次编辑时重新绘制所有文本,这会减慢应用程序的速度,尤其是在有大量文本的情况下的属性。有关实现核心文本编辑器的更有效方法,请阅读 富文本编辑 :选项主题:逐行绘制。
Apple’s SimpleTextInput sample code, uses Draw text all at once in single
CTFrameRef
object: This is the simplest options as you can get core text to just draw everything in one block. The only downside of this is that it can be inefficient as recreatingCTFrameRef
on every keystroke and redrawing all the text every time it is edited will slow your app down especially if there is a lot of text plus a lot of attributes.For more efficient ways of implementing Core text editor read Rich Text Editing : The choices topic:Draw line by line.
我已经看到了,它没有实现所有方法,可能这就是他们这么说的原因。根据您的项目和需要,您可以使用和扩展它。
I have seen it, It does not implement all methods, may be that is the reason they are saying it. Depends on your project and need, you can use and expand it.