ios 如何检测设备是否是 iPhone 5?

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

How to detect if the device is an iPhone 5?

iosxcode

提问by hanimal_p

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

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

I am trying to add a new view to an existing ios4 project to handle the new iphone5 screen size.

我正在尝试向现有的 ios4 项目添加新视图以处理新的 iphone5 屏幕尺寸。

However I dont have an iphone here to test on and the code I am using to test the screen size isnt working, just wondering if there is another way of detecting the device type??

但是我这里没有 iphone 可以测试,我用来测试屏幕尺寸的代码不起作用,只是想知道是否有另一种检测设备类型的方法?

NSLog(@"%f", [ [ UIScreen mainScreen ] bounds ].size.height);

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
    if([UIScreen mainScreen].bounds.size.height == 568.0)
    {
        //move to your iphone5 storyboard
        [self changeView:splashScreenBIGV viewH:splashScreenH animLength:SCREEN_CHANGE_ANIM_LENGTH];
   }
    else{
        //move to your iphone4s storyboard
        [self changeView:splashScreenV viewH:splashScreenH animLength:SCREEN_CHANGE_ANIM_LENGTH];            
    }
}

回答by DataPriest

For my universal app, Forex App, I'm simply using the screen height detection concept like so:

对于我的通用应用程序Forex App,我只是使用屏幕高度检测概念,如下所示:

CGSize screenSize = [[UIScreen mainScreen] bounds].size;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    if (screenSize.height > 480.0f) {
        /*Do iPhone 5 stuff here.*/
    } else {
        /*Do iPhone Classic stuff here.*/
    }
} else {
    /*Do iPad stuff here.*/
}

回答by rsswtmr

Answer is here. Basically, you don't. Use the new constraint layout system in iOS 6. You'll be chasing your tail if you have to rev your layout for every new device with a different screen size/resolution.

答案在这里。基本上,你没有。在 iOS 6 中使用新的约束布局系统。如果您必须为每台具有不同屏幕尺寸/分辨率的新设备调整布局,您将陷入困境。