swift - UIScreen.main.nativeBounds 与 x 和 y 坐标有何关系?
问题描述
如果我print
UIScreen.main.nativeBounds.height
返回2048
我的 iPad 模拟器,那很好。但这与x and y coordinates
? 例如,屏幕中间是x: 0, y: 0
。如果我向左移动,x coordinates
我使用减号,比如x: -100
,如果我向右移动,我使用加号,比如x: 100
。
在我看来,这意味着它UIScreen.main.nativeBounds.height
除以 2,以便我可以在x: -1024
和之间移动x: 1024
。那是对的吗?好吧,似乎不是因为这段代码:
portrait = gui.addPortrait(width: 80, height: 80, x:-350 , y: 180)
addChild(portrait)
将带我到设备 x 轴的远端,如下所示:
这意味着总数x-axis
必须是总共 750 左右。1024怎么了?我想我一定误解了它x-coordinates
与UIScreen.main.nativeBounds.height
. 我想了解这一点的原因是因为我想x position
动态设置它以使其适用于所有设备。类似的东西x: -(UIScreen.main.nativeBounds.height / 3)
。我错过了什么?
解决方案
相比之下UIScreen.bounds
,指定“[t] 屏幕的边界矩形,以点为单位”(docs),UIScreen.nativeBounds
指定“[t] 物理屏幕的边界矩形,以像素为单位”(docs)。
因此,您需要借助以下方法将值转换为点UIScreen.nativeScale
:
let width = round(UIScreen.main.nativeBounds.width / UIScreen.main.nativeScale)
let height = round(UIScreen.main.nativeBounds.height / UIScreen.main.nativeScale)
推荐阅读
- python - 比较两个列表并在发生更改时打印出来
- angularjs - 如何将 ng-if 逻辑写入控制器
- asp.net - Asp.Net RDLC ReportViewer 内存问题
- javascript - 使用 PHP 和 AJAX 在数据库中增加值
- grafana - 如何使用 Grafana 正确监控 AWS 上的 ELB 延迟?
- javascript - 在 UI 中更改时更改 reducer 上的复选框数组的状态
- css - 在 prestashop 中缩小 CSS 和 JS
- javascript - firebase auth 是否可以同时更新用户和自定义声明?
- sql - 如何计算表中的实例数(Countifs)
- javascript - 未捕获的错误:#90211 ExtensionName 错误 - 使用 FusionCharts 的 Node.JS、Heroku、JavaScript 应用程序