【发布时间】:2014-09-29 04:59:32
【问题描述】:
由于某种原因,这不起作用,因为我使用 iOS 8 更新到最新的 xcode。它无法识别
([[UIScreen mainScreen] scale] == 2.0)&
([[UIScreen mainScreen] bounds].size.height == 568.0)
// Indicates game is running on iPad
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CCLOG(@"Running on iPad");
// it doesn´t recognize this any more
if ([[UIScreen mainScreen] scale] == 2.0) {
CCLOG(@"Running on iPad Retina");
} else {
CCLOG(@"Running on iPad 2");
}
} else {
CCLOG(@"Running on iPhone");
// it doesn´t recognize this any more
if ([[UIScreen mainScreen] bounds].size.height == 568.0) {
CCLOG(@"Running on iPhone 5");
} else {
CCLOG(@"Running on iPhone 4/4S");
}
}
【问题讨论】:
-
您使用了哪些设备?你在 iPad Retina 上试过这个
[[UIScreen mainScreen] scale] == 2.0吗? -
不要比较没有 epsilon 的浮点数 ;)。不知道这是不是这里的错误,但你不应该这样做。
-
@WaqasRaja 我尝试了所有模拟器... ipad 2、ipad air、ipad Retina、iphone 4s、iphone 5、iphone 5s、iphone 6、iphone 6 plus。在 ipad 上运行时,它们都转到 ipad 2 部分,在 iphone 上运行时,它们都转到 iphone 4/4s 部分。
-
更新:由于某种原因,它现在开始适用于 ipad 视网膜模拟器......但仍然不适用于 iphone 5/iphone5s/iphone6/iphone6plus
-
bounds.height 它是一个浮点数,你可以尝试将它转换成一个整数来比较它: NSInteger screenHeight_Int=screenHeight;并比较这个数字 if (screenHeight_Int==568)... etc
标签: cocos2d-iphone xcode5 ios8 xcode6