【问题标题】:([[UIScreen mainScreen] scale] == 2.0) & ([[UIScreen mainScreen] bounds].size.height == 568.0) not working([[UIScreen mainScreen] scale] == 2.0) & ([[UIScreen mainScreen] bounds].size.height == 568.0) 不工作
【发布时间】: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


【解决方案1】:

您需要添加对 iPhone 5 的支持。为此,您需要将名为 Default-568h@2x.png 的启动图像添加到您的项目中。如果没有此图像,iOS 将在兼容模式下运行应用程序,即高度 = 468

这个问题在前面的其他问题中问过

how-to-add-iphone-5-large-screen-support-to-ios-apps-in-xcode

How to develop or migrate apps for iPhone 5 screen resolution?

【讨论】:

  • 我知道。我已经在使用名为 Default-568h@2x.png 的启动图像。我从 iOS 6 开始就一直在使用它……我的意思是,在我从 Xcode 5 更新到 Xcode 6 之前,一切正常。然后问题就开始了
  • 更新:我刚刚在 Xcode 5.1 上尝试了我的代码,并且 [[UIScreen mainScreen] bounds].size.height == 568.0 运行良好。 Xcode 6 中的什么导致了这个问题,我该如何解决?
猜你喜欢
  • 2012-09-06
  • 2013-07-02
  • 1970-01-01
  • 1970-01-01
  • 2012-09-26
  • 2021-06-20
  • 2011-10-30
  • 1970-01-01
  • 2017-01-25
相关资源
最近更新 更多