[英]How to get size of default keyboard for current device without it being displayed?
I am working on custom keyboard extenssion for iOS. 我正在为iOS开发自定义键盘扩展。 The keyboard's size should match that of default system keybaord on each device. 键盘的大小应与每个设备上默认系统键盘的大小匹配。
For purposes of accompanied app I need to know what is the size of default system keyboard (in portrait and landscape) without actually displaying the keyboard. 为了附带的应用程序,我需要知道默认系统键盘的大小(纵向和横向)是多少,而无需实际显示键盘。 Is there a way? 有办法吗?
Sure, I can measure size of keyboard in simulator on all devices a and than just use it as constant. 当然,我可以在所有设备上的模拟器中测量键盘的大小,而不仅仅是将其用作常量。 But then if a new device is released the app will not work on it properly - its keyboard size will not be amoung constants. 但是,如果发布了新设备,则该应用将无法在其上正常运行-其键盘大小将不会是常数。
Having never created a Keyboard Extension myself I'm going off of what would make sense to me. 我自己从来没有创建过键盘扩展程序,所以我将放弃对我来说有意义的功能。 I would recommend coming up with a layout for your keyboard that is consistent and have auto layout resize it to fill the space. 我建议您为键盘设置一个一致的布局,并让其自动布局调整其大小以填充空间。 If you're not using Interface Builder I'd recommend checking your view (or superview) in viewDidLoad
and seeing if it has already been sized for you. 如果您不使用Interface Builder,建议您在viewDidLoad
检查您的视图(或超级视图),并查看它是否已经为您调整大小。
No, the keyboard size can't be determined without actually showing it. 不可以,除非实际显示键盘尺寸,否则无法确定。 In any app, the current keyboard size should be determined by UIKeyboardFrameBeginUserInfoKey in a notification observer each time notified by UIKeyboardDidShowNotification. 在任何应用中,每次由UIKeyboardDidShowNotification通知时,当前键盘的大小都应由通知观察器中的UIKeyboardFrameBeginUserInfoKey确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.