What is the height of iPad's onscreen keyboard?

前端 未结 12 2069
傲寒
傲寒 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: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.

提交回复
热议问题