简体   繁体   中英

How to get size of default keyboard for current device without it being displayed?

I am working on custom keyboard extenssion for 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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