【问题标题】:game works well on all devices but iPad 2, why?游戏在除 iPad 2 之外的所有设备上运行良好,为什么?
【发布时间】:2015-01-25 05:04:24
【问题描述】:

我正在使用 Swift 并使用 SpriteKit 创建了一个基本游戏,其中方块在屏幕上反复向下移动,并且当点击时精灵节点会“跳跃”。比较简单。 除了 iPad 2 之外,游戏在包括 iPad air 和 iPad Retina 在内的所有设备上都可以正常运行和显示。

当我在 iPad 2 模拟器上运行游戏时,方块太大了,它们之间没有空间,节点也太大了,点击时只能在屏幕上跳跃半厘米。游戏一团糟。

为什么会这样?有没有办法在代码中指定:if 该设备是 iPad 2,以这种方式格式化和调整所有内容?还是有其他方法可以解决这个问题?

【问题讨论】:

    标签: ios ipad swift sprite-kit


    【解决方案1】:

    iPad 2 的分辨率与第一代 iPad(第一代)相同,因此分辨率比例为 1.0。您需要做的就是检查 iPad 的分辨率,然后根据结果做您需要的事情。只需添加此扩展程序,使用非常简单:

    extension UIDevice{
        var iPad2: Bool {
            userInterfaceIdiom == .pad && UIScreen.main.scale == 1
        }
        var iPadRetina: Bool {
            userInterfaceIdiom == .pad && UIScreen.main.scale == 2
        }
    }
    

    用法:

    if UIDevice.current.iPadRetina {
        // do whatever you need for the iPad with Retina Screens (2x)
    }
    if UIDevice.current.iPad2 {
        // do whatever you need for the iPad 2 without Retina (1x)
    }
    

    【讨论】:

    • 谢谢。你会如何为 iPhone 6 plus 做到这一点?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 2017-04-06
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多