iPad 屏幕键盘的高度是多少?
我在这里寻找两个数字:纵向高度和横向高度。不要以厘米或英寸为单位回答,而以像素为单位。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
纵向高度是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.
答案是:这取决于。
我知道键盘有 16 种不同的高度,并且可以处于任何位置。
它的不同之处在于:
我已附上一张显示一些不同可能配置的图像。
我认为您不想枚举所有 16 种可能性,而是想观察
UIKeyboardWillShowNotification
/UIKeyboardWillHideNotification
和UIKeyboardDidChangeFrameNotification
(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:
I have attached an image showing some different possible configurations.
Rather than enumerating all 16 possibilities, I think you want to observe
UIKeyboardWillShowNotification
/UIKeyboardWillHideNotification
andUIKeyboardDidChangeFrameNotification
(iOS 5.0+), and then get the keyboard's frame from those events.在 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.
您可以从 will/did show/hide 键盘通知返回的 userInfo 字典中获取键盘高度,如 UIWindow 类提供的 (参考指南链接)。这是比硬编码更好的获取高度的方法,因为您可以获得以下好处:
事实上,这个问题的答案给出了一个确切的数字,很可能是通过查看这本字典中返回的结果来得到这个数字的!
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:
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!
我对此页面上的几个答案投了反对票,因为它们具有危险的误导性。
当然,在 iOS 8 中,您不能使用硬编码的键盘高度。
这是我在 iPhone 上运行的应用程序,以说明我的原因。
拿起你的尺子,告诉我,屏幕键盘的高度是多少……?
啊...你做不到,对吗?
如果用户打开屏幕键盘顶部的自动输入栏(顺便说一下,这会触发第二个“
keyboardWillShow
”事件),高度可能会有所不同。iPad 上的屏幕键盘也是如此。
底线:抱歉,各位,您必须在
keyboardWillShow
事件中测量键盘高度。否则你会遇到问题。
顺便说一句,不要忘记上面代码中对
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..?
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.
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
UIView
s 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
您可以通过编程方式找到这一点(如果您没有设备,则通过模拟器)。
http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html#//apple_ref/doc/uid/TP40009542-CH5-SW1
You can find this out programmatically (through the simulator if you dont have a device).
http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html#//apple_ref/doc/uid/TP40009542-CH5-SW1
高度为:
肖像 = 264
风景 = 352
Heights are:
PORTRAIT = 264
LANDSCAPE = 352
在 iOS 7 中,对于 iPad,横向为 402,纵向为 314
In iOS 7, for iPad it is 402 for Landscape and 314 for Portrait
我不知道它是什么,但你可以很容易地弄清楚它。
在 iPad 上浏览到带有以下内容的页面...
JavaScript
HTML
单击按钮(在调出屏幕键盘后),它应该会告诉您高度。对另一个方向重复上述步骤。
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
HTML
Click the button (after you have brought up the on screen keyboard), and it should tell you the height. Repeat for the other orientation.
iOS 7 中存在一个问题,即横向模式下高度和宽度无法交换,但该问题在 iOS 8 中得到了解决。
因此,下面的代码片段始终返回 iOS7 或 iOS8 的高度,从而消除了代码中特定于版本的检查。
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.
我认为其他答案中解决的问题比解决的问题还要多。例如,您最终可以使用以下键盘:
当您在 iOS 9 上单击 iPad 键盘上的“隐藏”按钮时,会发生这种情况。此键盘在通知中仍具有
完整
尺寸来自Mike Gledhill
答案的信息。 (UIKeyboardFrameEndUserInfoKey
中键盘高度高于 300)。我必须从设备高度中减去键盘的 y 轴原点,才能得出正确的值。
我可以在 iOS9 上使用 iPhone 和 iPad 两种方向。
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 fromMike Gledhill
answer. (inUIKeyboardFrameEndUserInfoKey
height of keyboard is higher than 300).I had to subtract y-axis origin of keyboard from device height, to come to correct value.
Works for me on iOS9 with iPhones and iPads in both orientations.
我创建了这个表格,其中包含 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.