ios 检测 iphone 5 4" 屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12535471/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:18:50  来源:igfitidea点击:

Detect iphone 5 4" screen

iphoneobjective-ciosxcode

提问by Hackmodford

Possible Duplicate:
How to detect iPhone 5 (widescreen devices)?

可能的重复:
如何检测 iPhone 5(宽屏设备)?

Is there a way I can detect if the current device is the iphone 5? More specifically if it's using the new 4" screen?

有没有办法检测当前设备是否是 iphone 5?更具体地说,如果它使用的是新的 4" 屏幕?

回答by Hell_Ghost

Use this

用这个

#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)

回答by bioffe

I think you should concentrate on preferred display mode, rather than detecting iPhone5. Who knows what devices Apple will manufacture, but if your software supports that mode, it will be futureproof.

我认为您应该专注于首选显示模式,而不是检测 iPhone5。谁知道 Apple 将生产哪些设备,但如果您的软件支持该模式,它将是面向未来的。

BOOL isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));

In the future, folks might want to change preferred display mode on the fly. For example disconnect AppleTV from 720p tv and plug to 1080p, without restarting the app of course.

将来,人们可能希望即时更改首选显示模式。例如,断开 AppleTV 与 720p 电视的连接并插入 1080p,当然无需重新启动应用程序。

回答by Comradsky

Add this code in your initializtion:

在您的初始化中添加此代码:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
     if(UIScreenOverscanCompensationScale==1136/640){
             //move to your iphone5 storyboard
             [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)];
  }
     else{
             //move to your iphone4s storyboard
             [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)];
  }
}

This was an answer posted by me in another question here.

这是由我在另一个问题张贴解答这里

回答by Comradsky

Add this code to your application:

将此代码添加到您的应用程序:

if ([UIScreen mainScreen].scale == 2.f && screenHeight == 568.0f)
    {// iPhone 5 code}
else
    {// previous version code}