从屏幕上删除键盘而不调用resignFirstResponder [英] removing keyboard from Screen without calling resignFirstResponder

查看:130
本文介绍了从屏幕上删除键盘而不调用resignFirstResponder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIWindow 上添加了一个自定义视图( NotifyView )并带有一个关闭按钮(将其从的UIWindow )。
当PUSH通知进入时,会添加此视图 didReceiveRemoteNotification
有几种情况我可以在任何屏幕上,而我的键盘是UP 的UITextField / 的UITextView
在此阶段,如果推送到,键盘后面的 UIWindow 上会添加 NotifyView
我想在收到PUSH后辞职,所以我可以:

I have a custom View (NotifyView) added on UIWindow with a dismiss button(which remove it from UIWindow). This view is added when a PUSH notification comes in didReceiveRemoteNotification there are several cases when I could be on any screen, and my keyboard is UP via UITextfield/UITextview. At this stage if a push comes, the NotifyView is added on UIWindow behind the keyboard. I want to resign the keyboard once the PUSH is received so for that I could:


  • 发布通知 NSNotificaitonCenter 重新签名所有textfields / textviews(如果有人 firstResponder )。为此,我必须保持活动指针指向所有控制器中当前活动的textfield / textview。

  • post a Notification with NSNotificaitonCenter to resign all textfields/textviews (if anyone is firstResponder). For this I have to keep active pointer to the currently active textfield/textview in all controllers.

在AppDelegate中创建一个变量并将活动的textfields / textviews分配给它和PUSH,以及 resignFirstResponder 那些在PUSH上。

make a variable in AppDelegate and assign the active textfields/textviews to it and on PUSH, and resignFirstResponder of those on PUSH.

这两个解决方案都需要更改所有控制器的代码,我正在寻找更通用的东西,如:

Both of the solutions would require making changes to all controller's code and I am looking for something more generic like:


  • 可能有任何我可以通过接收PUSH从屏幕上删除键盘的方式

  • 或者我可以获取应用程序的当前firstResponder并明确地重新签名。

这些可能是通用解决方案。

these could be generic solutions.

如果有人可以促进这个思考过程或某人有这种情况的任何直接解决方案。

It would be really helpful if someone could facilitate this thought process or someone have any immediate solution for this case.

推荐答案

您可以使用以下方法

[[[UIApplication sharedApplication] keyWindow] endEditing:YES]

这篇关于从屏幕上删除键盘而不调用resignFirstResponder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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