简体   繁体   English

获取自定义键盘的高度(iOS 8)

[英]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. 我需要根据用户已激活的默认键盘的高度来调整几个UI元素的位置。 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 (eg SwiftKey), the height returns as 0. How would I get the height of the custom keyboard? 但是,当我将此代码与自定义键盘(例如SwiftKey)一起使用时,高度返回为0。如何获得自定义键盘的高度? Sorry if this has already been answered, but I haven't been able to find an answered thread yet... Thanks! 抱歉,如果已经回答了这个问题,但是我还没有找到答案的话题...谢谢!

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? 事实证明,由于某些未知原因,我在手机上测试的自定义键盘(SwiftKey)具有三个keyboardWillShow回调... SwiftKey / iOS 8的编码错误? 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: 按照顺序,三个回调中的每个回调上的UIKeyboardFrameEndUserInfoKey都返回以下高度:

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. 我使用了第三个回调中的信息,并且能够正确更新我的UI元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM