如何从iOS键盘扩展中检测到通过点击“发送”等操作清除了文本字段在iMessage中? [英] How to detect from iOS keyboard extension that a textfield is cleared via actions like hitting "Send" in iMessage?

查看:206
本文介绍了如何从iOS键盘扩展中检测到通过点击“发送”等操作清除了文本字段在iMessage中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iOS键盘应用程序中,我目前有一个文本建议栏,就像默认的iOS 8键盘的建议栏一样。每当用户执行清除文本字段的操作时(例如,某人在iMessage或Whatsapp上点击发送时),我想清除建议栏上的所有文字。

In my iOS keyboard app, I currently have a text suggestions bar much like the default iOS 8 Keyboard's suggestion bar. 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,).

由于点击发送是而不是按键,我想知道是否有方法在清除文本字段时从键盘检测到。

As hitting "Send" is not a keystroke, I was wondering if there is way to detect from the keyboard when a textfield is cleared.

我试过检测空文或新行\ n ,但到目前为止这还没有奏效。

I have tried detecting empty text "" or new line "\n", but so far this has not worked.

编辑:我知道这可以通过第三方iOS键盘实现,如此处所示(这是来自主题板

I do know that this is possible through 3rd party iOS Keyboard, as seen the case here (this is from Themeboard)

在点击发送之前,请注意建议栏中的文字。

Before hitting send, note the text in the suggestion bar.

点击发送后立即。建议栏已清除。

Immediately after hitting "send". The suggestion bar is cleared.

推荐答案

当在消息中按下发送按钮时,将在您的<$上调用 textDidChange:回调c $ c> UIInputViewController 子类。此时, UIInputViewController的 documentContextAfterInput documentContextBeforeInput 属性子类的 textDocumentProxy 属性将为nil或空字符串。当您知道为什么文本字段被清除时,您可以推断出发生这种情况的大多数情况,您应该清除当前的下一个单词预测。

When the send button is pressed in Messages, the textDidChange: callback will be called on your UIInputViewController subclass. At that point, both the documentContextAfterInput and documentContextBeforeInput properties of your UIInputViewController subclass's textDocumentProxy property will be nil or the empty string. 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: @""];
    }
}

这篇关于如何从iOS键盘扩展中检测到通过点击“发送”等操作清除了文本字段在iMessage中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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