Kevin Zhang
Kevin Zhang

Reputation: 111

Get height of custom keyboard (iOS 8)

I need to adjust the positioning of several UI elements based on the height of the default keyboard the user has active. I know how to get the height of the default system keyboard:

keyboardHeight = (sender.userInfo![UIKeyboardFrameBeginUserInfoKey] as NSValue).CGRectValue().height

However, when I use this code along with a custom keyboard (e.g. SwiftKey), the height returns as 0. How would I get the height of the custom keyboard? Sorry if this has already been answered, but I haven't been able to find an answered thread yet... Thanks!

Upvotes: 1

Views: 963

Answers (1)

Kevin Zhang
Kevin Zhang

Reputation: 111

Solved it! It turns out that the custom keyboard I was testing on my phone (SwiftKey) has THREE keyboardWillShow callbacks for some unknown reason... Bad coding on SwiftKey's/iOS 8's part? Anyways, I wrote my code in a way that I only used the first callback, but the third callback returned a sender that had the correct info. In order, UIKeyboardFrameEndUserInfoKey on each of the three callbacks returned the height of:

No keyboard (0.0)
System's keyboard (also SwiftKey's keyboard without the autocomplete frame above the main keyboard)
Custom keyboard

I used the info from the third callback and was able to update my UI elements correctly.

Upvotes: 1

Related Questions