KeyboardWillShow 被调用两次
我有一个带有键盘通知的视图,例如 keyboardWillShow
和 keyboardWillHide
我使用的通知处理的所有代码均取自Apple的示例代码"KeyboardAccessory"
当我第一次输入时这个视图,一切正常。
但是,当我从子视图返回到此视图时,每次点击一个按钮时都会显示:
[myTextField becomeFirstResponder];
keyboardWillShow
和 keyboardWillHide
方法每次都会被调用两次。
真的很困惑,
有人能帮我解决这个问题吗?
真的很感激!
I have a view with keyboard notifications such as keyboardWillShow
and keyboardWillHide
All the codes handles with the notification I use is taken from Apple's sample code "KeyboardAccessory"
When I first enter this view, everything works fine.
But when I return to this view from its subviews, every time I tap a button that says:
[myTextField becomeFirstResponder];
the keyboardWillShow
and keyboardWillHide
methods will be called twice every time.
It's really confusing,
Could anyone helps me with this?
really appreciate!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想发布您的代码。
如果您的方法被调用两次,很可能您正在多次注册键盘通知,并且在您认为需要时没有删除观察者。
在 viewWillAppear: 中添加观察者并在 viewWillDisappear: 中删除它,看看会发生什么。
You might want to post your code.
If your methods are being called twice, most likely, you are registering for the keyboard notifications multiple times and not removing the observer when you think you are.
Add your observer in viewWillAppear: and remove it in viewWillDisappear: and see what happens.
当显示自定义键盘(如 SwiftKey)时,它在 iOS 8 上被调用两次。
在第一次调用时,它可能准备显示,因此
CGSize KeyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
的 keybaord 高度将为 0。第二次调用将具有正确的键盘高度,因此如果您需要调整内容插图,您可以检查返回的键盘高度是否> > 0 在计算你的插入之前。
此外,每当用户更改键盘时都会调用它。
It is called twice on iOS 8 when a custom keyboard, like SwiftKey is being shown.
On the first call, it probably prepares to show, so
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
will have a keybaord height of 0.The second call will have the correct keyboard height, so if you need to adjust content insets, you can check that the height of keyboard returned is > 0 before calculating your insets.
Also, it will be called whenever user changes keyboard.
对我来说,更改
inputAccessoryView
会触发另一个keyboardWillShow
调用,因为输入附件视图的高度会影响整体键盘高度。For me, changing
inputAccessoryView
would fire another call ofkeyboardWillShow
because the height of an input accessory view affects the overall keyboard height.