检测isIpad是否更好的方法? [英] Better way to detect if isIpad?

查看:27
本文介绍了检测isIpad是否更好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通用应用,可以根据用户使用的设备更改屏幕布局.它似乎工作得很好,但我让一位用户打电话(并向我发送屏幕截图)他的 iPhone 4 向他展示了 iPad 视图而不是 iPhone 视图.我无法在我们周围的任何手机上复制它,但我想知道自从 iOS 4.3 发布后是否有更好的方法来做到这一点.

I have an universal app that changes the screen layout based on what device the user has. It seems to work pretty good, but I've had one user call in (and send me screen shots) of his iPhone 4 showing him the iPad view instead of the iPhone view. I haven't been able to duplicate it on any of the phones we have around here, but I'm wondering if there there is a better way to do this since iOS 4.3 has come out.

+(BOOL)isIpad{
  return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
}

或者,有没有办法检测屏幕尺寸?我主要使用它来确定表格中元素的宽度,但如果 Apple 推出带有视网膜显示屏的 iPad 3,那么让应用程序相应地调整所有内容会很好.
如果应用程序是纵向或横向,也很有用.使它像 WPF 中的元素一样锚定到边缘.

Alternately, is there just a way to detect screen size? I mostly use this to determine how wide elements in a table should be, but if Apple comes out with iPad 3 with retina display, it would be nice to have the app just adjust everything accordingly.
Also useful if the app is in portrait or landscape. Make it so that it just anchors to the edges like elements in WPF.

推荐答案

当为通用应用加载 XIB 时,这,或者你已经在做的,似乎是唯一的方法:

When loading XIBs for a universal app this, or what you're already doing, seems to be the only way:

NSString *xibName = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)?@"SomeView~iPad":@"SomeView";

至于屏幕尺寸,这应该可以:

As for screen size this should work:

CGRect screenSize = [[UIScreen mainScreen] bounds];

这篇关于检测isIpad是否更好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆