What is the height of iPad's onscreen keyboard?

前端 未结 12 2071
傲寒
傲寒 2020-12-08 03:45

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.

相关标签:
12条回答
  • 2020-12-08 04:33

    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.

    0 讨论(0)
  • 2020-12-08 04:37

    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.

    0 讨论(0)
  • 2020-12-08 04:42

    Heights are: PORTRAIT = 264 LANDSCAPE = 352

    0 讨论(0)
  • 2020-12-08 04:44
    - (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
    }
    
    0 讨论(0)
  • 2020-12-08 04:44

    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.

    0 讨论(0)
  • 2020-12-08 04:44

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

    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.

    0 讨论(0)
提交回复
热议问题