【问题标题】:Does resolution width and height value swap on device rotation?分辨率宽度和高度值是否会在设备旋转时交换?
【发布时间】:2021-04-28 01:26:35
【问题描述】:

我想知道这两个在设备旋转时是否会改变它们的值。

float currentResolutionX = Screen.currentResolution.width;
float currentResolutionY = Screen.currentResolution.height;

Debug.Log(currentResolutionX + "x" + currentResolutionY) // 1080x1920

// now let's rotate the device to landscape

Debug.Log(currentResolutionX + "x" + currentResolutionY) // ??? 1920x1080 ???

我正在为纵向和横向模式制作不同的 UI。因此,要正确计算 UI 元素的大小,我需要知道是否必须使用交换值。 例如,假设设备的分辨率为 1080x1920。当它旋转时,它会在内部变为 1920x1080 吗?我的意思是Screen.currentResolution.width 会更改为 1920 还是保持 1080?我不确定 os 如何处理旋转。

【问题讨论】:

  • cmets 是否反映了您的测试结果?
  • 第一个评论,是的,第二个没有经过测试,我正在尝试了解它是否会调试这样的值。不幸的是,我无法测试它,所以我必须依靠你的经验。
  • 为什么不在 Unity Editor 中进行测试?你可以通过交换resouliton来测试它。您可以通过此属性查看手机方向Screen.orientation
  • @SeLeCtRa 我使用您提到的属性进行了调试,并且似乎在两种情况下初始分辨率都没有改变。 Screen.currentResolution 宽度和高度保持不变。

标签: android ios unity3d user-interface screen-resolution


【解决方案1】:

我使用@SeLeCtRa 的建议进行了调试。结果Screen.currentResolution 的宽度和高度保持不变。

【讨论】:

    猜你喜欢
    • 2017-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-08
    相关资源
    最近更新 更多