keyboardWillShow called twice

独自空忆成欢 提交于 2019-11-30 03:03:29

问题


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!


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/8082455/keyboardwillshow-called-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!