iPad 键盘尺寸

发布于 2024-08-31 01:06:44 字数 51 浏览 6 评论 0原文

我在苹果文档中找到了iPhone的键盘界限,但找不到iPad的键盘界限。请你帮助我好吗?

I have found the iPhone's keyboard bounds in the apple documentation, but I can't find the iPad's keyboard bounds. Could you please help me?

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

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

发布评论

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

评论(4

夏至、离别 2024-09-07 01:06:45

代码中的整个答案如下所示。首先,您需要注册通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];

还有更多这里< /a>.请注意,您还需要删除它们(使用removeObserver)。

然后你需要一个方法来获取通知以获取大小。请注意,尺寸一开始并未旋转(因为 UIWindow 不会旋转。它的内容会旋转)。

- (void) keyboardDidShow:(NSNotification*)notification {
        CGRect keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
        NSLog(@"keyboard frame raw %@", NSStringFromCGRect(keyboardFrame));

        UIWindow *window = [[[UIApplication sharedApplication] windows]objectAtIndex:0];
        UIView *mainSubviewOfWindow = window.rootViewController.view;
        CGRect keyboardFrameConverted = [mainSubviewOfWindow convertRect:keyboardFrame fromView:window];
        NSLog(@"keyboard frame converted %@", NSStringFromCGRect(keyboardFrameConverted));
}

显然,如果您通过其他方式引用了 mainSubviewOfWindow,请使用它。

The entire answer in code looks like this. First you need to register for the notifications:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];

and there are more here. Note that you'll need to get rid of them, too (use removeObserver).

Then you need a method that gets the notification to get the size. Note that the size is, at first, not rotated (since the UIWindow doesn't rotate. Its contents do).

- (void) keyboardDidShow:(NSNotification*)notification {
        CGRect keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
        NSLog(@"keyboard frame raw %@", NSStringFromCGRect(keyboardFrame));

        UIWindow *window = [[[UIApplication sharedApplication] windows]objectAtIndex:0];
        UIView *mainSubviewOfWindow = window.rootViewController.view;
        CGRect keyboardFrameConverted = [mainSubviewOfWindow convertRect:keyboardFrame fromView:window];
        NSLog(@"keyboard frame converted %@", NSStringFromCGRect(keyboardFrameConverted));
}

Obviously, if you have a reference to your mainSubviewOfWindow by some other means, use it.

源来凯始玺欢你 2024-09-07 01:06:45

iPhone 的纵向为 216 像素,横向为 162 像素,iPad 的纵向为 264 像素,横向为 352 像素。这对于 2010 年的美国键盘有效。

这些大小对于其他语言可能有所不同,并且对于美国也可能会发生变化。

For iPhone in portrait 216 pixels, landscape 162 pixels, for iPad in portrait it's 264 pixels and in landscape 352 pixels. This is valid for US keyboard in 2010.

These sizes can be different for other languages, and might change for US as well.

冰雪梦之恋 2024-09-07 01:06:45

请注意,如果用户选择在 iPad 上使用“拆分”键盘,则不会触发 UIKeyboardDidShowNotification/*UIKeyboardDidHideNotification* 通知。相反,UIKeyboardDidChangeFrameNotification 通知将在显示和隐藏时触发。您必须分析 keyboardFrame.origin.y 才能弄清楚到底发生了什么(显示或隐藏)。

Please note that if user choose to use "split" keyboard on iPad, then UIKeyboardDidShowNotification/*UIKeyboardDidHideNotification* notifications will not be fired. Instead, UIKeyboardDidChangeFrameNotification notification will be fired on both show and hide. You will have to analyze keyboardFrame.origin.y to figure out what exactly happen (show or hide).

緦唸λ蓇 2024-09-07 01:06:45

如果其他人需要它,我刚刚找到它。
键盘通知用户信息键

I just found it if somebody else needs it.
Keyboard Notification User Info Keys

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