返回错误的设备方向

时间:2017-12-23 18:05:30

标签: ios iphone swift orientation

我想我在UIDevice.orientation变量中发现了一个错误。

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(true)
    if UIDevice.current.orientation.isPortrait{
        print("Orientation is Portrait")
    }
    else{
        print("Orientation is Landscape")
    }
}

如果我手持设备(Iphone 5),一切正常,但如果它平放在桌子上,我会得到#34; Orientation is Landscape"即使所有内容都显示在纵向中,设备本身也不会旋转。 有没有办法对此做点什么?

//编辑:此测试在按钮操作中也失败。

2 个答案:

答案 0 :(得分:2)

除了肖像和风景之外还有更多的方向。你正在检查肖像,并假设其他一切都是风景。它不是。在这种情况下,实际方向可能是“正面朝上”。

答案 1 :(得分:1)

在肖像和风景旁边还有第三个选项UIDevice.current.orientation.isFlat,您只在检查肖像