为什么iPad的键盘高度在横向模式下是1024px?

时间:2021-08-16 16:08:34

I ran into this issue earlier in the week and again just now. I'm in the process of setting my keyboard offset for when the keyboard appears on the screen when the user is in landscape mode of an iPad. iPads have a dimension of 1024 x 768.

我在这周的早些时候遇到了这个问题。我正在设置键盘偏移量,当用户处于iPad的横向模式时,键盘出现在屏幕上。ipad的尺寸是1024 x 768。

- (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: 1024.000000 Width: 352.000000
}

How is it that the height of the keyboard can be 1024? This would mean that the keyboard is now covering the entire screen. I would assume that the height should be 352, and the width should be 1024. Is this a bug?

键盘的高度怎么会是1024呢?这意味着键盘现在覆盖了整个屏幕。假设高度是352,宽度是1024。这是一个错误吗?

1 个解决方案

#1


10  

From http://developer.apple.com/library/ios/documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/doc/uid/TP40006817-CH3-SW27

从http://developer.apple.com/library/ios/documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html # / / apple_ref / doc / uid / TP40006817-CH3-SW27

UIKeyboardFrameBeginUserInfoKey

UIKeyboardFrameBeginUserInfoKey

The key for an NSValue object containing a CGRect that identifies the start frame of the keyboard in screen coordinates. These coordinates do not take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it.

包含CGRect的NSValue对象的键,该键在屏幕坐标中标识键盘的开始帧。这些坐标不考虑由于界面朝向的改变而应用于窗口内容的任何旋转因子。因此,您可能需要在使用矩形之前将其转换为窗口坐标(使用convertRect:fromWindow: method)或查看坐标(使用convertRect:fromView: method)。

#1


10  

From http://developer.apple.com/library/ios/documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/doc/uid/TP40006817-CH3-SW27

从http://developer.apple.com/library/ios/documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html # / / apple_ref / doc / uid / TP40006817-CH3-SW27

UIKeyboardFrameBeginUserInfoKey

UIKeyboardFrameBeginUserInfoKey

The key for an NSValue object containing a CGRect that identifies the start frame of the keyboard in screen coordinates. These coordinates do not take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it.

包含CGRect的NSValue对象的键,该键在屏幕坐标中标识键盘的开始帧。这些坐标不考虑由于界面朝向的改变而应用于窗口内容的任何旋转因子。因此,您可能需要在使用矩形之前将其转换为窗口坐标(使用convertRect:fromWindow: method)或查看坐标(使用convertRect:fromView: method)。