iOS - 锁定屏幕时多次调用 UI KeyboardWillShowNotification

标签 ios objective-c nsnotificationcenter

我正在 viewdidload 上创建通知UIKeyboardWillShowNotification 并在 上删除它 View 将消失 .

当键盘出现在屏幕上并按预期调用一次通知时,我锁定了屏幕。通知称为 4 时间并创建不需要的功能。

为什么要调用通知?我该如何预防这种情况?

我正在以这种方式在 viewdidload 中添加 Observer 以进行通知

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillShow:)
                                             name:UIKeyboardWillShowNotification
                                           object:nil];

编辑:
如果我将应用程序发送到后台而不是锁定屏幕,则结果相同。

最佳答案

同样的事情也发生在我身上

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];

我在按钮点击时展示了一个 View Controller 。每次我展示 Viewcontroller viewdidload 时都会调用它添加 addObserver。所以该方法被多次调用。

关于iOS - 锁定屏幕时多次调用 UI KeyboardWillShowNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39346133/

相关文章:

ios - 在 iOS 中使用 XMPP 将新用户注册到 Openfire 服务器

ios - 如何在聚焦时调整 UISearchController.searchBar 的大小问题?

objective-c - Swift 桥接返回父类对象而不是派生类

ios - 如何声明弱通知

ios - UIKeyboardWillShow/WillHide 通知,如何知道这些通知何时发送给已注册的观察者

ios - ios删除avaudioplayer循环延迟

ios - 动态改变UIPageControl.appearance的点的背景颜色

ios - 方法没有可见的@interface声明选择器

iphone - PerformSelectorInBackgroundThread 和 NSTimer

ios - 通知观察员不在 swift 闭包中工作