iPad 屏幕键盘的高度是多少?

发布于 2024-10-03 15:47:41 字数 50 浏览 5 评论 0原文

我在这里寻找两个数字:纵向高度和横向高度。不要以厘米或英寸为单位回答,而以像素为单位。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

ㄟ。诗瑗 2024-10-10 15:47:41

纵向高度是264,而横向高度是352。

我知道这是一个迟到的答案,但我自己刚刚遇到这个问题。

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.

非要怀念 2024-10-10 15:47:41
- (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
}
- (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
}
胡渣熟男 2024-10-10 15:47:41

答案是:这取决于

我知道键盘有 16 种不同的高度,并且可以处于任何位置。

它的不同之处在于:

  1. 横向/纵向、
  2. 网络视图/非网络视图、
  3. 亚洲字符选择样式、常规语言
  4. 拆分键盘/非拆分

我已附上一张显示一些不同可能配置的图像。

示例 ipad 键盘配置

我认为您不想枚举所有 16 种可能性,而是想观察 UIKeyboardWillShowNotification/ UIKeyboardWillHideNotificationUIKeyboardDidChangeFrameNotification (iOS 5.0+),然后从这些事件中获取键盘的框架。

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.

十二 2024-10-10 15:47:41

在 iPad 上,键盘尺寸还取决于语言(例如日语键盘较高)。以编程方式查询它的另一个原因。

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.

九厘米的零° 2024-10-10 15:47:41

您可以从 will/did show/hide 键盘通知返回的 userInfo 字典中获取键盘高度,如 UIWindow 类提供的 (参考指南链接)。这是比硬编码更好的获取高度的方法,因为您可以获得以下好处:

  • 设备独立性(iPhone/iPod 或 iPad)
  • 分辨率独立性(iPhone 3G 屏幕/视网膜显示屏/iPad 显示屏/未来显示屏)。
  • 键盘类型/样式独立性(不同的屏幕键盘可能有不同的尺寸)。

事实上,这个问题的答案给出了一个确切的数字,很可能是通过查看这本字典中返回的结果来得到这个数字的!

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!

如梦亦如幻 2024-10-10 15:47:41

我对此页面上的几个答案投了反对票,因为它们具有危险的误导性。

当然,在 iOS 8 中,您不能使用硬编码的键盘高度。

这是我在 iPhone 上运行的应用程序,以说明我的原因。

拿起你的尺子,告诉我,屏幕键盘的高度是多少……?

在此处输入图像描述

啊...你做不到,对吗?

如果用户打开屏幕键盘顶部的自动输入栏(顺便说一下,这会触发第二个“keyboardWillShow”事件),高度可能会有所不同。

iPad 上的屏幕键盘也是如此。

底线:抱歉,各位,您必须keyboardWillShow 事件中测量键盘高度。

否则你会遇到问题。

- (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);

}

顺便说一句,不要忘记上面代码中对 convertRect 的调用。

如果没有它,我发现在运行 iOS 8 的 iPad 上,有时键盘会被报告为高度为 1024 像素。

还有一件事...

今天,我我正在开发我编写的自定义控件,该控件出现在 iPhone/iPad 屏幕的底部,并意识到我没有考虑屏幕键盘的高度。

我不想添加 KeyboardWillShow/Hide 通知,因为这个小控件是通用的,可以从我的任何屏幕调用。

我的解决方案是使用免费的 SVProgressHUD 控件中出色的 visibleKeyboardHeight 函数来查找屏幕键盘的高度(如果当前可见)。

该控件还需要屏幕键盘的高度,因此其通知消息 UIView 将垂直居中显示。

它很有效......所以如果您确实需要一种快速获取键盘高度的方法,请获取此代码的副本,然后查看SVProgressHUD.m< /strong> 文件。

从 GitHub 下载 SVProgressHUD

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

¢好甜 2024-10-10 15:47:41

高度为:
肖像 = 264
风景 = 352

Heights are:
PORTRAIT = 264
LANDSCAPE = 352

等风也等你 2024-10-10 15:47:41

在 iOS 7 中,对于 iPad,横向为 402,纵向为 314

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

相思碎 2024-10-10 15:47:41

我不知道它是什么,但你可以很容易地弄清楚它。

在 iPad 上浏览到带有以下内容的页面...

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>

单击按钮(在调出屏幕键盘后),它应该会告诉您高度。对另一个方向重复上述步骤。

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.

熟人话多 2024-10-10 15:47:41

iOS 7 中存在一个问题,即横向模式下高度和宽度无法交换,但该问题在 iOS 8 中得到了解决。

因此,下面的代码片段始终返回 iOS7 或 iOS8 的高度,从而消除了代码中特定于版本的检查。

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

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;
}
濫情▎り 2024-10-10 15:47:41

我认为其他答案中解决的问题比解决的问题还要多。例如,您最终可以使用以下键盘:

在此处输入图像描述

当您在 iOS 9 上单击 iPad 键盘上的“隐藏”按钮时,会发生这种情况。此键盘在通知中仍具有完整尺寸来自 Mike Gledhill 答案的信息。 (UIKeyboardFrameEndUserInfoKey 中键盘高度高于 300)。

我必须从设备高度中减去键盘的 y 轴原点,才能得出正确的值。

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

我可以在 iOS9 上使用 iPhone 和 iPad 两种方向。

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.

北座城市 2024-10-10 15:47:41

我创建了这个表格,其中包含 iPhone 和 iPad 键盘的高度,包括横向和纵向模式,以及工具栏打开和关闭的情况。

我什至解释了如何在代码中使用这些尺寸 此处

请注意,只有在布局视图之前需要知道键盘的尺寸时,才应使用这些尺寸。否则,其他答案的解决方案效果更好。

输入图片此处描述

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文