尝试以横向方式检测iPhone 6 Plus

时间:2014-09-14 13:41:14

标签: ios swift

我的应用程序有一个今天的小部件,我一直在设置代码的布局(不使用自动布局)但是,我需要检测用户何时使用iPhone 6 Plus。原因是因为在6 Plus的通知中心,边缘周围有一个边框,切断了我的小部件中的标签(横向)。

问题在于我一直在试图弄清楚屏幕在景观中的高度值。

这是我现在的代码:

        var height = UIScreen.mainScreen().bounds.size.height

    if UIDevice.currentDevice().orientation.isLandscape && height == 414 {
        totalBudgetDisplay.frame.origin.x = UIScreen.mainScreen().bounds.width - 250
        currentBudgetDisplay.frame.origin.x = UIScreen.mainScreen().bounds.width - 250
        budgetNameDisplay.frame.origin.x = 80
        warningLabel.center = view.center
        button.frame = CGRectMake(0, 0, view.bounds.width, view.bounds.height)
    }

这是横向屏幕高度的正确值吗?如果是这样,为什么标签仍然没有移动?

1 个答案:

答案 0 :(得分:0)

您的代码很好但是UIDevice.currentDevice()。orientation.isLandscape只是没有为您提供正确的值。

似乎没有用于检测扩展设备方向的防弹解决方案。

请查看此答案,了解可能的解决方法 - https://stackoverflow.com/a/26023538/2797141