6

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?

Charles Sprayberry
  • 7,741
  • 3
  • 41
  • 50
rae148
  • 87
  • 1
  • 5
  • possible duplicate of [Adjusting interface when keyboard appears for UITextField or UITextView](http://stackoverflow.com/questions/402658/adjusting-interface-when-keyboard-appears-for-uitextfield-or-uitextview) – jtbandes Aug 18 '11 at 03:31
  • 1
    I did resize my view but the problem is that, in iPad, according to the language of the keyboard, the height changed. And seems like there is no notification when the height of keyboard is changed as the keyboard is already visible. – rae148 Aug 26 '11 at 08:57
  • Really? I thought all keyboards were the same height. – jtbandes Aug 26 '11 at 09:00
  • In iPad, Japanese and Chinese keyboard show a suggested list on top of the keyboard.. which make it taller... – rae148 Aug 26 '11 at 09:01

2 Answers2

2

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.

Community
  • 1
  • 1
Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
1

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

Daniel Krom
  • 9,751
  • 3
  • 43
  • 44