What is the height of iPad's onscreen keyboard?
Asked Answered
L

13

53

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.

Lauralee answered 18/11, 2010 at 10:40 Comment(4)
You can easily make two screenshots and measure.Kenji
OP please change the correct answer to one of the answers that determines the frame programmatically. Also, you cannot specify pixels, but rather points on iOS.Tonga
If you are looking for height, but not the programmatically found height, then this is a poorly worded question. Do you want the English Keyboard? Spilt keyboard? Height with autofill enabled? Or even the new iOS 8 keyboards? Plus, if you don't want a programatic answer, don't ask the question on stackoverflow. Most developers that come across this question and the accepted answer are going to be misguided. From a development standpoint, you should always find the height programmatically. From a design standpoint, find a pixel ruler and measure it.Othella
possible duplicate of iPad keyboard dimensionsPictish
T
121

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.

Thrombin answered 23/12, 2010 at 13:58 Comment(8)
Don't worry about the answer being late. I will accept this answer as soon as I've validated the height. :)Lauralee
This is correct for the English keyboard. Sorry for not validating the height sooner.Lauralee
This is a bad answer. You never want to hard code these pixel values because they could be changed in future releases. For example, Apple could tweak the dimensions of the keyboards by a few pixels, they could introduce new forms of keyboard (such as the split keyboard) or different sizes for different languages. They could also release different resolution screens (such as the retina display). All these cases could cause the desired effect of your code to break. It would be much better to use one of the dynamic solutions offered by the other answers.Seep
@JamesBedford It's not a bad answer, it's the correct answer. You don't even know what I needed those measurements for. Perhaps I'm a graphics designer and need the height of the keyboard to draw a proper mockup. Hardcoding these values in an app may be bad practice, but it has nothing to do with the quality of the answer.Lauralee
Ok, fair point! I guess your question is very direct haha! I think we've both managed to make our points here. :)Seep
@LeonS, This answer is not incorrect. Your answer is for iPhone. This question is about the iPad.Lauralee
@ErikB I'm sorry to disagree but I'm with James on that one. This is like asking "what is the height of a human" and answering with a number of inches. It depends on a number of factors, none of which are outlined in the original question. It's not a bad answer per say but it is definitely not the correct answer - with all due respect.Kristofer
@Kristofer When this question was asked there was only one available iPad and the keyboard height did not differ between the available iOS versions. Different languages had different height keyboards, but the majority of all keyboards had the same height as the English keyboard. Today things are very different and the usefulness of this answer is much lower, but historically it had relevance as you can see by the number of upvotes.Lauralee
G
55
- (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
}
Gonophore answered 8/6, 2011 at 3:4 Comment(8)
+1 for this answer- shows how the height is returned as what is supposed to be the width when in Landscape. I noticed I was getting a height of 1024 as height and 352 as width, in landscape, which seemed weird to me, until I saw this answer. ThanksCrepuscule
Answer is incomplete.Nickelous
How is this incomplete/not obvious?Providence
This is why, because you need this: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil]; However my problem is, this app is landscape and this code doesn't seem to take that into effect. It says my Height is 1024 and my width is 396.Eisenstein
@Eisenstein - Did you ever figure out out what was happening with the landscape app? Seems to be fixed on iOS 8 but on iOS 7 I get the same issue and just assume the smallest dimensions is the height... kind of hacky but it seems to work.Soybean
@Alex- Yeah, no I didn't I basically did the same thing if I remember correctly.Eisenstein
@Alex - Seems like the hack you suggested makes more sense. The one with the smaller dimension could be considered as height. At least can get rid of the iOS version specific check in the code..Adenoid
If you enable the KeyboardAccessory view (undo/redo/autocomplete) then the keyboard frame height is more than 352. I get 398 on iPad2 with iOS 9.Kristofer
H
30

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.

Horseshoe answered 6/1, 2013 at 2:16 Comment(0)
S
17

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.

Skerl answered 9/1, 2011 at 10:27 Comment(1)
Chinese keyboards are also taller, as they are words to choose from, based on input.Calabria
S
6

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!

Seep answered 22/6, 2011 at 23:11 Comment(1)
Sure, but snippets have already been provided by others so that's ok! :)Seep
T
5

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

Tanta answered 6/1, 2015 at 13:17 Comment(0)
P
3

You can find this out programmatically (through the simulator if you dont have a device).

http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html#//apple_ref/doc/uid/TP40009542-CH5-SW1

Pannell answered 18/11, 2010 at 15:46 Comment(0)
D
2

Heights are: PORTRAIT = 264 LANDSCAPE = 352

Decoder answered 10/12, 2010 at 14:49 Comment(3)
This is the kind of answer I'm looking for. If you can provide the height in landscape I will accept it as my answer. :)Lauralee
The portrait height is 264 for the English keyboard, so your answer was incorrect, but thanks anyway.Lauralee
You are correct. Sorry. The way I measured them I wasn't taking into account the 20 px of the status bar. I've updated my answer now.Decoder
S
2

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

Septuagenarian answered 19/11, 2013 at 11:12 Comment(1)
It may be in your application & context but this is not a universal fact. See answers from @Horseshoe and others. It depends on many things including language, accessory toolbar, 3rd party keyboards, etc.Kristofer
A
1

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;
}
Adenoid answered 17/3, 2015 at 7:15 Comment(0)
D
0

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.

Dupleix answered 18/11, 2010 at 10:44 Comment(3)
I don't have an iPad and I don't have a web server, so this is not so easily done for me. I was hoping that someone could just provide the numbers.Lauralee
This is great on the ipad but doesn't seem to work on the iphone because it centers it.Flossi
This solution impossible in ios/safari. Because keyboard is not resizing main web view.Dandle
D
0

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.

Dg answered 22/4, 2016 at 8:11 Comment(0)
D
0

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

Domella answered 26/12, 2020 at 18:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.