[英]How does a keyboard extension know that the document proxy has changed?
Keyboard extensions on iOS are subclasses of the UIInputViewController
class and have the textDocumentProxy
property to interact with the underlying document. iOS上的键盘扩展是
UIInputViewController
类的子类,并具有textDocumentProxy
属性以与基础文档交互。 The textDocumentProxy
object exposes some important traits of the document, like the autocapitalization type. textDocumentProxy
对象公开了文档的一些重要特征,如自动资本化类型。 The question is, how does the keyboard extension know when the underlying document changes? 问题是,键盘扩展如何知道基础文档何时发生变化?
For example, when I tap to compose a new message in the Messages app, the “To” field uses different input traits than the message body input box. 例如,当我点击在消息应用程序中撰写新消息时,“收件人”字段使用与消息正文输入框不同的输入特征。 But since the keyboard doesn't dissapear when switching focus from one field to the other, the text document proxy object changes on the fly.
但是,由于在将焦点从一个字段切换到另一个字段时键盘不会消失,因此文本文档代理对象即时更改。 Can the keyboard extension notice such a change?
键盘扩展可以注意到这样的变化吗?
I've tried watching both the textDocumentProxy
and [[self textDocumentProxy] autocapitalizationType]
properties through KVO, but that doesn't work. 我已经尝试通过KVO观察
textDocumentProxy
和[[self textDocumentProxy] autocapitalizationType]
属性,但这不起作用。 Checking the autocapitalizationType
property using a timer reveals the change, but obviously I'd like to avoid a polling solution. 使用计时器检查
autocapitalizationType
属性会显示更改,但显然我想避免使用轮询解决方案。
My UIInputViewController
supports the UITextInput
protocol, which has a textDidChange
method. 我的
UIInputViewController
支持UITextInput
协议,该协议具有textDidChange
方法。 From textDidChange
, I compare self.textDocumentProxy
with my own self.currentTextProxy
property. 从
textDidChange
,我将self.textDocumentProxy
与我自己的self.currentTextProxy
属性进行比较。 When the two differ, I update self.currentTextProxy
, then refresh my GUI based upon the self.textDocumentProxy
's UITextInputTraits
. 当两者不同时,我更新
self.currentTextProxy
,然后根据self.textDocumentProxy
的UITextInputTraits
刷新我的GUI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.