swift - 设备倒置时 UIDevice.current.orientation 不一致
问题描述
当我切换UIDevice.current.orientation
和打印UIScreen.main.bounds.height
或width
我得到正确的值时,除了设备倒置时。这里height
和width
值是相反的。比如在一个iPhone 8 plus模拟器中,awidth
是414, aheight
是736。但是当模拟器倒置时,突然awidth
是736, aheight
是414。代码如下:
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")
}
这给出了以下输出:
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
Portrait 和 PortraitUpsidedown 应该有相同的height
和width
,但是有一个不一致的地方。在纵向模式下,短边应该是,width
所以我猜倒置方向有问题。还是我误解了这是如何工作的?
解决方案
推荐阅读
- android - 如何检查 Espresso 中的待处理意图数组?
- javascript - Create-React-App 在 Edge 浏览器中不起作用
- ibm-cloud - IBM Cloud:在“经典基础架构”下设置时如何通过 API 访问 DNS 条目
- python-3.x - 如何将字典中的值与嵌套字典中的值关联?
- r - package expss:以与值标签相同的格式打印多个响应的标签
- arrays - 使用数组和通配符自动过滤 VBA
- pandas - 当其他列满足条件时计算列中的行总和
- java - Spring Boot 升级后“找不到提供程序 com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule”
- python - 用python分析每月销售额
- node.js - 基于 websockets 和 Mqtt 协议的 MQTT 消息传递