xcode 在模拟器上检测 iPhone 6/Plus 时遇到问题

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

Having issue with detect iPhone 6/Plus on simulator

iosobjective-ciphonexcode

提问by Mc.Lover

I am trying to build a version of my app specifically for iPhone 6 and 6 Plus , whereas I don't have any hardware , I have to test on the simulator ! but it seems , simulator has a strange bug ! first and for most I get screen resolutions and scales , by this code :

我正在尝试专门为 iPhone 6 和 6 Plus 构建我的应用程序版本,而我没有任何硬件,我必须在模拟器上进行测试!但似乎,模拟器有一个奇怪的错误!首先,对于大多数人来说,我通过以下代码获得屏幕分辨率和比例:

    UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f",
      NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);

so here is how detect iPhone 6 and 6Plus (Portrait mode):

所以这里是如何检测 iPhone 6 和 6Plus(纵向模式):

#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 667)

#define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 736)

the problem is ! when I lunch my app on iPhone6/Plus simulator , compiler gives me the sceen information of iPhone 4" display :

问题是 !当我在 iPhone6/Plus 模拟器上吃午饭时,编译器给了我 iPhone 4" 显示器的屏幕信息:

    2014-09-28 12:32:08.153 WOD[2924:42290] 
Screen bounds: {{0, 0}, {320, 568}}, Screen resolution: <UIScreen: 0x7fa15be0f9b0; bounds = {{0, 0}, {320, 568}}; mode = <UIScreenMode: 0x7fa15bd0d4a0; 
size = 640.000000 x 1136.000000>>, scale: 2.000000, nativeScale: 2.000000

But it works fine on new project ! (I cannot create a new project and start over again !). I cleaned code, delete build folder, change project's name,and reset Simulator contents settingbut still gives me the information of 4" display ! .

但它在新项目上运行良好!(我无法创建新项目并重新开始!)。I cleaned code, delete build folder, change project's name, 和 resetSimulator contents setting但仍然给我 4" 显示器的信息!.

I have checked this Q/Abut answers require a real device !

我已经检查了这个Q/A但答案需要一个真实的设备!

回答by Mc.Lover

The main reason I faced with this problem was I build my application with Xcode 5and open it with Xcode 6

我面临这个问题的主要原因是我构建我的应用程序Xcode 5并打开它Xcode 6

Solution :

解决方案 :

Add Launch Image for Retina HD 5.5 and 4.7 :

为 Retina HD 5.5 和 4.7 添加启动图像:

enter image description here

在此处输入图片说明

Now you can detect iPhone 6/Plus on simulator without having a real device :

现在您可以在模拟器上检测 iPhone 6/Plus,而无需真正的设备:

#define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 667)
 #define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 736)

回答by yoshitech

Just in case you need to detect iPhone 6/6Plus in landscape, use this.

万一您需要在横向检测 iPhone 6/6Plus,请使用它。

 #define iPhone6 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 667)
 #define iPhone6Plus ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && MAX([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width) == 736)