简体   繁体   English

如何在不显示当前设备的情况下获取默认键盘的大小?

[英]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.

相关问题 设备大小快速变化时,如何获取子视图的当前大小? - how to get current size of a subview when device size changes in swift? 获取键盘尺寸而不显示它 - Get Keyboard size without showing it SwiftUI / iOS | 在没有 NSNotification 的情况下获取键盘大小 - SwiftUI / iOS | Get keyboard size without NSNotification 如何在未注册开发者计划的情况下获取 iOS 应用程序的大小? - How to get the size of an iOS app without being enrolled in the developer program? 如何在iOS中获取当前设备和当前平台? - How to get Current Device & Current platform in iOS ? 如何获取当前显示为NSString的视图? - How to get the view that is currently being displayed as an NSString? iOS:如何获取当前可见的键盘类型? - iOS: How to get the current visible keyboard type? 在/ other /方向上以及隐藏键盘的情况下获取当前iOS设备的键盘高度 - Get keyboard height of current iOS device in the /other/ orientation and whilst the keyboard is hidden 如何知道当前的大小类以及我的按钮是否显示? - How to know the current size classes and if my button is displayed? 为iPhone设备中的内容可编辑div获取电子邮件键盘而不是默认键盘 - Get email keyboard instead of default keyboard for content editable div in iPhone device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM