设备颠倒时,UIDevice.current.orientation不一致

时间:2019-12-26 14:38:15

标签: swift uidevice uideviceorientation

当我切换UIDevice.current.orientation并打印UIScreen.main.bounds.heightwidth时,我得到了正确的值,但设备处于颠倒状态时除外。 heightwidth的值在这里是相反的。例如,在iPhone 8 plus模拟器中,width是414,而height是736。但是当模拟器倒置时,width突然是736,而{{1} }是414。代码如下:

height

这将提供以下输出:

switch UIDevice.current.orientation {
    case .landscapeLeft, .landscapeRight:
        print("?landscape", " width: ", UIScreen.main.bounds.width, " height: ", UIScreen.main.bounds.height)
    case .portrait:
        print("?Portrait", " width: ", UIScreen.main.bounds.width, " height: ", UIScreen.main.bounds.height)
    case .portraitUpsideDown:
        print("?UPSIDEDOWN", " width: ", UIScreen.main.bounds.width, " height: ", UIScreen.main.bounds.height)
    default:
        print("other")
}

portrait和portraitUpsidedown应该具有相同的?landscape width: 736.0 height: 414.0 ?UPSIDEDOWN width: 736.0 height: 414.0 ?landscape width: 736.0 height: 414.0 ?Portrait width: 414.0 height: 736.0 height,但存在不一致之处。在纵向模式下,短边应为width,因此我想上下颠倒的方向有问题。还是我误解了它的工作原理?

0 个答案:

没有答案