What is the height of iPad's onscreen keyboard?

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

    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;
    }
    

提交回复
热议问题