简体   繁体   English

键盘扩展如何知道文档代理已更改?

[英]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.textDocumentProxyUITextInputTraits刷新我的GUI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何知道用户是否更改了标签? - How to know if a user has changed tab? ipad如何知道键盘已被隐藏 - ipad how to know keyboard has been hidden 有谁知道是否可以在iOS 8的自定义键盘扩展中使用麦克风? - Does anyone know if it is possible to use the Microphone in a custom Keyboard extension in iOS 8? 如何检测iOS 8中键盘的高度是否发生了变化? - How can I detect if the height of the keyboard has changed in iOS 8? 如何知道iPhone用户SIM卡是否已更改? - How to know if iPhone user SIM Card has changed? iOS知道文件何时更改 - iOS know when file has changed iOS swift4,单击多个UITextField,键盘显示,向上移动的UIButton不知道为什么向下移动 - iOS swift4, Click multiple UITextFields,Keyboard show, the UIButton that has moved up does not know why it moved down 如何正确检查用户是否已启用“允许完全访问”自定义键盘扩展名 - How to properly check if user has enabled “Allow Full Access” to custom keyboard extension 如何检查我的ios8自定义键盘扩展是否具有开放访问权限? - How can I check does my ios8 custom keyboard extension have open access? 如何使用文档提供程序扩展? - How to use Document Provider Extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM