简体   繁体   English

如何通过在iMessage中点击“发送”等操作从iOS键盘扩展中检测到文本字段被清除?

[英]How to detect from iOS keyboard extension that a textfield is cleared via actions like hitting “Send” in iMessage?

In my iOS keyboard app, I currently have a text suggestions bar much like the default iOS 8 Keyboard's suggestion bar. 在我的iOS键盘应用程序中,我目前有一个文本建议栏,就像默认的iOS 8键盘的建议栏。 I would like to clear all text on the suggestion bar whenever the user does something that clears the text field (for example, when someone hits " Send " on iMessage or Whatsapp,). 每当用户执行清除文本字段的操作时(例如,当某人在iMessage或Whatsapp上点击“ 发送 ”时),我想清除建议栏上的所有文本。

As hitting "Send" is not a keystroke , I was wondering if there is way to detect from the keyboard when a textfield is cleared. 因为点击“发送” 不是击键 ,我想知道在清除文本字段时是否有从键盘检测的方法。

I have tried detecting empty text "" or new line "\\n" , but so far this has not worked. 我已经尝试检测空文本""或新行"\\n" ,但到目前为止这没有用。

Edit: I do know that this is possible through 3rd party iOS Keyboard, as seen the case here (this is from Themeboard ) 编辑:我知道这可以通过第三方iOS键盘,如这里所见(这是来自Themeboard

Before hitting send, note the text in the suggestion bar. 在点击发送之前,请注意建议栏中的文字。
在发送之前

Immediately after hitting "send". 点击“发送”后立即。 The suggestion bar is cleared. 建议栏已清除。
点击发送后

When the send button is pressed in Messages, the textDidChange: callback will be called on your UIInputViewController subclass. 在Messages中按下发送按钮时,将在UIInputViewController子类上调用textDidChange: callback。 At that point, both the documentContextAfterInput and documentContextBeforeInput properties of your UIInputViewController subclass's textDocumentProxy property will be nil or the empty string. 此时, UIInputViewController子类的textDocumentProxy属性的documentContextAfterInputdocumentContextBeforeInput属性将为nil或空字符串。 While you don't know why the textfield was cleared, you can probably infer for most cases where this occurs that you should clear your current next word prediction. 虽然你知道为什么文本框被清除,你也许可以推断大多数情况下,这种情况发生时,你应该清楚你目前的下一个单词预测。

- (void)textDidChange:(id<UITextInput>)textInput
{
    if ((!self.textDocumentProxy.documentContextBeforeInput && !self.textDocumentProxy.documentContextAfterInput) || ([self.textDocumentProxy.documentContextBeforeInput isEqualToString:@""] && [self.textDocumentProxy.documentContextAfterInput isEqualToString:@""])){
        //Implement code to clear the banner
        [self.keyboard.lblBanner setText: @""];
    }
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM