What is the height of iPhone's onscreen keyboard?
Keyboard height is 216pts for portrait mode and 162pts for Landscape mode.
Source
What is the height of iPad's onscreen keyboard?
The portrait height is 264 while the landscape height is 352.
I know this is a late answer, but I just came across this question myself.
iPhoneX and iPhone 8 keyboard height are different
The keyboard height for both iPhone X and iPhone 8 should be correct. I can only guess that maybe you have a problem in your code for locating the "red part", and your assumption was that the keyboard height was incorrect whereas the problem was actually in the location of the view. Now - the reason for the location problem? My second guess is the red part is pinned to the bottom safe area layout guide, which on the iPhone 8 is 0, but on the iPhone X is inset 34 points.
See this image to illustrate both the difference in keyboard heights and that it is possible to draw a rectangle just above the keyboard using the keyboard height from the keyboard height reported in the NSNotification
for the keyboardWillShow
method:
If you want to share your code / constraints for positioning the red view, I should be able to show you the problem.
--Edit: For anyone interested to know how I extract the drew the red rectangle, I go into it in a blog post here.
How to get height of Keyboard?
Swift
You can get the keyboard height by subscribing to the UIKeyboardWillShowNotification
notification. (Assuming you want to know what the height will be before it's shown).
Swift 4
NotificationCenter.default.addObserver(
self,
selector: #selector(keyboardWillShow),
name: UIResponder.keyboardWillShowNotification,
object: nil
)
@objc func keyboardWillShow(_ notification: Notification) {
if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
let keyboardRectangle = keyboardFrame.cgRectValue
let keyboardHeight = keyboardRectangle.height
}
}
Swift 3
NotificationCenter.default.addObserver(
self,
selector: #selector(keyboardWillShow),
name: NSNotification.Name.UIKeyboardWillShow,
object: nil
)
@objc func keyboardWillShow(_ notification: Notification) {
if let keyboardFrame: NSValue = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue {
let keyboardRectangle = keyboardFrame.cgRectValue
let keyboardHeight = keyboardRectangle.height
}
}
Swift 2
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
func keyboardWillShow(notification: NSNotification) {
let userInfo: NSDictionary = notification.userInfo!
let keyboardFrame: NSValue = userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue
let keyboardRectangle = keyboardFrame.CGRectValue()
let keyboardHeight = keyboardRectangle.height
}
Get height of iOS keyboard without displaying keyboard
A quick solution that you could use, is the same one used when you want to cache the keyboard (the first time you show it, you get a slight delay...). The library is here. The interesting bits:
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:field];
[field becomeFirstResponder];
[field resignFirstResponder];
[field removeFromSuperview];
So basically is showing it and then hiding it. You could listen for notifications and just get the height
without actually seeing it. Bonus: you get to cache it. :)
iOS foreign language keyboard heights?
iPhone 6 (9.0)
Portrait:
- English (predictive text disabled): 216
- English (predictive text minimized): 225
- Chinese (Simplified) - Handwriting: 252
- Emoji: 258
- English (predictive text maximized): 258
- Chinese (Simplified) - Pinyin - 10 Key: 283.5
Landscape:
- Chinese (Simplified) - Pinyin - 10 Key: 162
- English (predictive text disabled): 162
- English (predictive text minimized): 171
- Emoji: 194
- English (predictive text maximized): 194
- Chinese (Simplified) - Handwriting: 198
iPad Air (9.0)
Portrait:
- English (shortcut bar only): 55
- English (without shortcut bar): 265
- Emoji: 303
- English (with shortcut bar): 313
- Chinese (Simplified) - Handwriting (without shortcut bar): 406
- Chinese (Simplified) - Handwriting (with shortcut bar): 461
Landscape:
- English (without shortcut bar): 353
- Emoji: 391
- English (with shortcut bar): 398
- Chinese (Simplified) - Handwriting (without shortcut bar): 406
- Chinese (Simplified) - Handwriting (with shortcut bar): 461
Note: all values are ordered by size then name.
Note: shortcut bar refers to the iOS 9 Shortcut Bar and/or iOS 8's QuickType bar which is enabled/disabled by choosing the Predictive and Shortcuts options.
Related Topics
How to Dismiss the Keyboard When Editing a Uitextfield
How to Rotate Text for Uibutton and Uilabel in Objective-C
Iad Is Shutting Down. Should I Remove the Iad Framework from All My Applications
iOS - Uiimageview - How to Handle Uiimage Image Orientation
Uicollectionview: Must Be Initialized with a Non-Nil Layout Parameter
iOS 11 Navigation Bar Height Customizing
Dynamic Height Issue for Uitableview Cells (Swift)
How to Format a Double into Currency - Swift 3
iOS 9 Facebook Login Simulator -Canopenurl: Failed for Url: "Fbauth2:///" - Error: "(Null)"
How to Assign an Action for Uiimageview Object in Swift
iOS 8 Sdk: Modal Uiwebview and Camera/Image Picker
Extract Uiimage from Nsattributed String
Difference Between Protocol and Delegates
How to Detect If a Video File Was Recorded in Portrait Orientation, or Landscape in iOS
iOS App Freezes on Pushviewcontroller
Instruments Allocations Track Alloc and Dealloc of Objects of User Defined Classes