我有iOS应用程序,我正在使用this帖子中解释的尺寸指令。
我正在使用最新的Xcode(6.4)版本上的iOS模拟器进行测试。当我运行我的项目,并在设备选择上选择iPhone 4s时,项目将运行正确的检测消息和正确的故事板;如果我使用iPhone 5和iPhone 5s运行相同。但是当我选择iPhone 6或6 Plus时,我在这部分放置的检测和控制台日志会将iPhone检测为iPhone 5,并显示iPhone 5的故事板。我尝试检测分辨率(以CGRect为单位)使用NSLog在控制台日志中显示高度和显示,但无论模拟器显示的是具有正确大小的窗口,日志中都会显示iphone 5的分辨率大小。
我定义指令时有代码:
#define IS_IPHONE_4 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)480) < DBL_EPSILON)
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSILON)
#define IS_IPHONE_6 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)667) < DBL_EPSILON)
#define IS_IPHONE_6P (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)736) < DBL_EPSILON)
我检测到设备时有代码:
//Para detectar screen size
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if (IS_IPHONE_4)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"4sStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *vc =[storyboard instantiateInitialViewController];
self.window.rootViewController = vc;
NSLog(@"iPhone 4 storyboard loaded up.");
}
else
{
if(IS_IPHONE_5)
{
UIStoryboard *storyboard1 = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *vc2 =[storyboard1 instantiateInitialViewController];
self.window.rootViewController = vc2;
NSLog(@"iPhone 5 storyboard loaded up.");
}
else
{
if (IS_IPHONE_6)
{
UIStoryboard *storyboard1 = [UIStoryboard storyboardWithName:@"6Storyboard" bundle:[NSBundle mainBundle]];
UIViewController *vc2 =[storyboard1 instantiateInitialViewController];
self.window.rootViewController = vc2;
NSLog(@"iPhone 6 storyboard loaded up.");
}
else
{
if (IS_IPHONE_6P)
{
UIStoryboard *storyboard1 = [UIStoryboard storyboardWithName:@"6pStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *vc2 =[storyboard1 instantiateInitialViewController];
self.window.rootViewController = vc2;
NSLog(@"iPhone 6 plus storyboard loaded up.");
}
}
}
这是我的日志的退出,无论是iphone 5还是6或6plus,iPhone 4s的检测工作正常:
2015-09-04 15:44:55.823 denuncia[1737:156925] iPhone 5 storyboard loaded up.
我如何重新解决这个问题?我已经工作了很长时间,很快就会遇到麻烦......我非常感谢你的帮助。
答案 0 :(得分:0)
我使用此代码时遇到没有麻烦。尝试一下,如果它不起作用,请写下评论!
#define IS_IPHONE_4 ([UIScreen mainScreen].bounds.size.height == 480)
#define IS_IPHONE_5 ([UIScreen mainScreen].bounds.size.height == 568)
#define IS_IPHONE_6 ([UIScreen mainScreen].bounds.size.height == 667)
#define IS_IPHONE_6P ([UIScreen mainScreen].bounds.size.height == 736)
是的,就这么简单!
干杯