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
How to detect if the device is an iPhone 5?
提问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.*/
}