KeyboardWillShow 被调用两次

发布于 2024-12-14 19:04:39 字数 543 浏览 0 评论 0原文

我有一个带有键盘通知的视图,例如 keyboardWillShowkeyboardWillHide

我使用的通知处理的所有代码均取自Apple的示例代码"KeyboardAccessory"

当我第一次输入时这个视图,一切正常。

但是,当我从子视图返回到此视图时,每次点击一个按钮时都会显示:

[myTextField becomeFirstResponder];

keyboardWillShowkeyboardWillHide 方法每次都会被调用两次。

真的很困惑,

有人能帮我解决这个问题吗?

真的很感激!

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 技术交流群。

扫码二维码加入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.

软糖 2024-12-21 19:04:39

当显示自定义键盘(如 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.

凹づ凸ル 2024-12-21 19:04:39

对我来说,更改 inputAccessoryView 会触发另一个 keyboardWillShow 调用,因为输入附件视图的高度会影响整体键盘高度。

For me, changing inputAccessoryView would fire another call of keyboardWillShow because the height of an input accessory view affects the overall keyboard height.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文