开发者

Notification for change of iPad keyboard height

开发者 https://www.devze.com 2023-03-29 01:37 出处:网络
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.

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 t开发者_StackOverflow社区hat area....

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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消