What is the height of iPad's onscreen keyboard?

IpadKeyboardHeight

Ipad Problem Overview


I'm looking for two numbers here: the height in portrait and the height in landscape. Don't answer in cm or inches, but rather in pixels.

Ipad Solutions


Solution 1 - Ipad

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.

Solution 2 - Ipad

- (void) keyboardWasShown:(NSNotification *)nsNotification {
    NSDictionary *userInfo = [nsNotification userInfo];
    CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    NSLog(@"Height: %f Width: %f", kbSize.height, kbSize.width);
    // Portrait:	Height: 264.000000	Width: 768.000000
    // Landscape:	Height: 352.000000	Width: 1024.000000
}

Solution 3 - Ipad

The answer is: it depends.

I am aware of 16 different heights the keyboard can be, and it can be in any position.

It is different for:

  1. landscape/portrait,
  2. webview/non-webview,
  3. asian character selection style, regular language
  4. split keyboard / non-split

I have attached an image showing some different possible configurations.

sample ipad keyboard configurations

Rather than enumerating all 16 possibilities, I think you want to observe UIKeyboardWillShowNotification/UIKeyboardWillHideNotification and UIKeyboardDidChangeFrameNotification (iOS 5.0+), and then get the keyboard's frame from those events.

Solution 4 - Ipad

On the iPad, the keyboard size can also depend on the language (e.g. the japanese keyboard is taller). Another reason to query it programmatically.

Solution 5 - Ipad

You can get the keyboard height from the userInfo dictionary returned by the will/did show/hide keyboard notification, as provided by the UIWindow class (reference guide link). This is a much better way of getting the height than hard-coding because you get the following benefits:

  • Device independence (iPhone/iPod or iPad)
  • Resolution independence (iPhone 3G screen/retina display/iPad display/future displays).
  • Keyboard type/style independence (different on-screen keyboards may have difference sizes).

In fact, the answers to this question that give an exact number most likely got this number by looking at the results returned within this dictionary!

Solution 6 - Ipad

I've voted down a couple of answers on this page, as they are dangerously misleading.

Certainly, with iOS 8, you cannot use a hard-coded keyboard height.

Here's my app, running on an iPhone, to give my reason why.

Grab your ruler, and tell me, what is the height of the onscreen keyboard..?

enter image description here

Ahh... you can't do it, can you ?

The height can vary, if the user turns on the auto-type bar at the top of the onscreen keyboard (which, by the way, triggers off a second "keyboardWillShow" event).

The same is true for the onscreen keyboard on the iPad.

Bottom line: sorry folks, you must measure the keyboard height in a keyboardWillShow event.

You will hit problems otherwise.

- (void)keyboardWillShow:(NSNotification *)notification {

    NSDictionary *info = [notification userInfo];
    NSValue *kbFrame = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardFrame = [kbFrame CGRectValue];
    keyboardFrame = [self.view convertRect:keyboardFrame fromView:nil];
        
    CGFloat heightOfKeyboard = keyboardFrame.size.height;

    NSLog(@"The keyboard is now %d pixels high.", (int)heightOfKeyboard);

}

Btw, don't forget that call to convertRect in the code above.

Without it, I found that, on an iPad running in landscape with iOS 8, sometimes the keyboard would be reported as having a height of 1024 pixels..

Just one more thing...

Today, I was working on a custom control I'd written, which appears at the bottom of the iPhone/iPad screen, and realised I hadn't taken the onscreen keyboard height into consideration.

I didn't want to add keyboardWillShow/Hide notifications, as this little control was generic, able to be called from any of my screens.

My solution to find the height of the onscreen keyboard, if it was currently visible, was to use the excellent visibleKeyboardHeight function from the free SVProgressHUD control.

That control also needed the height of the onscreen keyboard, so its notification message UIViews would appear vertically-centered.

It worked a treat... so if you do need a quick'n'dirty method of grabbing the keyboard height, grab a copy of this code, and look in the SVProgressHUD.m file.

Download SVProgressHUD from GitHub

Solution 7 - Ipad

Solution 8 - Ipad

Heights are: PORTRAIT = 264 LANDSCAPE = 352

Solution 9 - Ipad

In iOS 7, for iPad it is 402 for Landscape and 314 for Portrait

Solution 10 - Ipad

There was an issue in iOS 7 where the height and width were not swapping in landscape mode, but the issue was fixed in iOS 8.

So, here is the piece of code that would always return the height for iOS7 or iOS8, thereby eliminating the version specific check in your code.

- (void)keyboardWasShown:(NSNotification*)aNotification
{
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    //Always gives the height as the height is of smaller dimension
    CGFloat height = (kbSize.height>kbSize.width)?kbSize.width:kbSize.height;
}

Solution 11 - Ipad

I don't know what it is, but you could figure it out easily enough.

Surf on your iPad to a page with this...

###JavaScript###

var totalHeight = window.innerHeight;
document.getElementById('what-is-my-height').onclick = function() {
  alert(totalHeight - window.innerHeight); 
};

###HTML###

<button id="what-is-my-height">Bring up keyboard, then push me</button>

Click the button (after you have brought up the on screen keyboard), and it should tell you the height. Repeat for the other orientation.

Solution 12 - Ipad

I think there are more troubles than are solved in others answers. For example, you can end up with this keyboard:

enter image description here

This happens when you click "hide" button on iPad keyboard on iOS 9. This keyboard has still full size in notification info from Mike Gledhill answer. (in UIKeyboardFrameEndUserInfoKey height of keyboard is higher than 300).

I had to subtract y-axis origin of keyboard from device height, to come to correct value.

- (void)keyboardWillShow:(NSNotification *)notification
    NSDictionary *info = [aNotification userInfo];
    CGRect keyboardFrame = [info[UIKeyboardFrameBeginUserInfoKey] CGRectValue];

    keyboardFrame = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    keyboardFrame = [self.view convertRect:keyboardFrame fromView:nil];
    CGFloat yPosition = keyboardFrame.origin.y;

    NSInteger height = [UIScreen mainScreen].bounds.size.height - yPosition;
 }   

Works for me on iOS9 with iPhones and iPads in both orientations.

Solution 13 - Ipad

I created this table which contains both the heights of iPhone and iPad keyboards, both for landscape and portrait mode, both with the toolbar on and off.

I even explained how you can use these dimensions in your code here.

Note that you should only use these dimensions if you need to know the keyboard's dimension before you layout the view. Otherwise the solutions from the other answers work better.

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionErik BView Question on Stackoverflow
Solution 1 - IpadthelawsView Answer on Stackoverflow
Solution 2 - Ipaduser629328View Answer on Stackoverflow
Solution 3 - Ipadjcampbell1View Answer on Stackoverflow
Solution 4 - IpadKris Van BaelView Answer on Stackoverflow
Solution 5 - IpadJames BedfordView Answer on Stackoverflow
Solution 6 - IpadMike GledhillView Answer on Stackoverflow
Solution 7 - IpadDominicView Answer on Stackoverflow
Solution 8 - IpadbornbnidView Answer on Stackoverflow
Solution 9 - IpadMaxView Answer on Stackoverflow
Solution 10 - IpadSwaroop SView Answer on Stackoverflow
Solution 11 - IpadalexView Answer on Stackoverflow
Solution 12 - Ipadkraag22View Answer on Stackoverflow
Solution 13 - IpadFederica BenacquistaView Answer on Stackoverflow