rae148
rae148

Reputation: 87

Notification for change of iPad keyboard height

I am trying to show a UITextField on top of the iPad keyboard.

I was able to get the height of the keyboard when it was presented with the notification.

However, in iPad, by change the language input of the keyboard -> most likely to Japanese, the height of the keyboard changed because a text-hypothesis area was shown on top of the keyboard, that caused my UITextfield hidden by that area....

Does anybody know how can I get the height changed notification or any other way?

Upvotes: 6

Views: 3918

Answers (2)

Daniel Krom
Daniel Krom

Reputation: 10058

Swift

The UIKeyboardDidShowNotification won't fire anymore the keyboard size change.

Use UIKeyboardWillChangeFrameNotification instead:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(instance.keyboardWillChange(_:)), name:UIKeyboardWillChangeFrameNotification, object: nil)

at the function:

let targetSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() 

Important: this event will be fired also when keyboard will open and will hide, can replace both UIKeyboardWillShowNotification and UIKeyboardWillHideNotification if only sizes are needed

Upvotes: 1

Dan Rosenstark
Dan Rosenstark

Reputation: 69757

The answer is that when you switch languages, the UIKeyboardDidShowNotification fires for each change, so you always get the updated height.

See my answer here on how to set up responses to the showing and hiding, and getting the height.

Upvotes: 2

Related Questions