xcode iOS 6 - 区分 iPhone 5 和其他设备?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12398798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 6 - Distinguishing between iPhone 5 and other devices?
提问by mhbdr
With the announcement of the iPhone 5 and new iPods today, I'm starting work on optimizing my app to take advantage of the new, extra screen space. I've already got to the point where my app isn't "letterboxed" anymore. I know it's early, but does anyone know how I could distinguish between the new, taller devices and the old ones?
随着今天 iPhone 5 和新 iPod 的发布,我开始着手优化我的应用程序以利用新的额外屏幕空间。我已经到了我的应用程序不再是“信箱”的地步。我知道现在还早,但有谁知道我如何区分新的、更高的设备和旧的设备?
Ideally, it would be something like this:
理想情况下,它会是这样的:
if (device is iPhone 5 or taller iPod touch) {
do stuff that is ideal for the taller screen
} else {
do what I've been doing before for the smaller screen
}
Thanks! I hope everyone else is also enjoying what Apple announced today as well!
谢谢!我希望其他人也能享受 Apple 今天宣布的内容!
采纳答案by overboming
On the top of my head, you can use bounds information for the UIScreen
[UIScreen mainScreen].bounds
and check the height or better the ratio of the screen.
在我的头顶上,您可以使用 UIScreen 的边界信息
[UIScreen mainScreen].bounds
并检查高度或更好的屏幕比例。
回答by Hashim MH
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
}
if(result.height == 568)
{
// iPhone 5
}
}
回答by Marco
- (BOOL)isTall
{
CGRect bounds = [[UIScreen mainScreen] bounds];
CGFloat height = bounds.size.height;
CGFloat scale = [[UIScreen mainScreen] scale];
return (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) && ((height * scale) >= 1136));
}
回答by codingrhythm
For those that the screen still returns 480 instead of 568, you need to add a new launch images with the new size in the summary tab of application settings.
对于屏幕仍然返回 480 而不是 568 的那些,您需要在应用程序设置的摘要选项卡中添加具有新大小的新启动图像。