当我切换UIDevice.current.orientation
并打印UIScreen.main.bounds.height
或width
时,我得到了正确的值,但设备处于颠倒状态时除外。 height
和width
的值在这里是相反的。例如,在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
,因此我想上下颠倒的方向有问题。还是我误解了它的工作原理?