iPhone XS Max和iPhone XR屏幕的物理尺寸。

3
随着苹果产品线的更新,我更新了软件并试图找出新设备屏幕的物理尺寸(像素)。
对于 iPhone XS,它很清楚:
- 宽度/高度为1125 / 2436个像素, - 缩放因子为3, - 在物理上宽度/高度为375 / 812个点(如 iPhone X)。
对于 iPhone XR,也很清楚:
- 宽度/高度为750 / 1624个像素, - 缩放因子为2, - 在物理上高度/宽度也为375 / 812个点。
但对于 iPhone XS Max,则不清楚:
- 苹果表示宽度/高度为1242 / 2688个像素,
但我的计算给出的数据与 iPhone XS 相同:
- 宽度/高度为1125 / 2436个像素, - 缩放因子为3, - 在物理上获得的宽度/高度点为375/812。
我认为使用 Device.Info.PixelScreenSize.Height 和 Device.Info.PixelScreenSize.Width,我将其除以 Device.Info.ScalingFactor,然后重新检查 Xamarin.Essentials,即 DeviceDisplay.ScreenMetrics,然后我也将其除以 Device.Info.ScalingFactor。
真相在哪里?应该采取什么数据才可靠?
附:抱歉使用了谷歌翻译。
 public partial class App : Application
        {
            public static int ScreenWidth;
            public static int ScreenHeight;
            public static Size ScreenSize;
            ...

2. AppDelegate.cs(应用程序代理)
 public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            App.ScreenWidth = (int)UIScreen.MainScreen.Bounds.Width;
            App.ScreenHeight = (int)UIScreen.MainScreen.Bounds.Height;
            App.ScreenSize = new Size(UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
            ...

3. MainPageViewModel.cs (这是一个C#文件名)
public class MainPageViewModel
    {
        public double DeviceHeightInPixels { get; set; }
        public double DeviceWidthPixels { get; set; }
        public double Coefficient { get; set; }
        public double PhysicalHeightInPixels { get; set; }
        public double PhysicalWidthInPixels { get; set; }
        public double DeviceHeightInPixelsFromMetrics { get; set; }
        public double DeviceWidthPixelsFromMetrics { get; set; }
        public int AppScreenHeight { get; set; }
        public int AppScreenWidth { get; set; }
        public double AppScreenSizeHight { get; set;}
        public double AppScreenSizeWidth { get; set; }

        public MainPageViewModel()
        {
            var metrics = DeviceDisplay.ScreenMetrics;

            DeviceHeightInPixels = Device.Info.PixelScreenSize.Height;
            DeviceWidthPixels = Device.Info.PixelScreenSize.Width;

            Coefficient = Device.Info.ScalingFactor;

            PhysicalHeightInPixels = DeviceHeightInPixels / Coefficient;
            PhysicalWidthInPixels = DeviceWidthPixels / Coefficient;

            DeviceHeightInPixelsFromMetrics = metrics.Height;
            DeviceWidthPixelsFromMetrics = metrics.Width;

            AppScreenHeight = App.ScreenHeight;
            AppScreenWidth = App.ScreenWidth;

            AppScreenSizeHight = App.ScreenSize.Height;
            AppScreenSizeWidth = App.ScreenSize.Width;
        }
    }

enter image description here


也许这个能帮到你:https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions - Swapnil Luktuke
是的,一切都在这里完美地显示和正确地呈现,我同意这一点。但为什么Device.Info.PixelScreenSize和DeviceDisplay.ScreenMetrics没有显示出来? - Vegi Woo
2个回答

8
编辑:
我认为你选择了错误的模拟器。XS Max按照你的期望提供正确的值。 这是一个简单的Swift代码(检查“nativeBounds”以获取实际大小):
    print("Name:\t\(UIDevice.current.name)")
    print("Size:\t\(UIScreen.main.bounds.size)")
    print("Scale:\t\(UIScreen.main.scale)")
    print("Native:\t\(UIScreen.main.nativeBounds.size)")

这是四个 X 模拟器的输出结果。
Name:   iPhone X
Size:   (375.0, 812.0)
Scale:  3.0
Native: (1125.0, 2436.0)

Name:   iPhone XR
Size:   (414.0, 896.0)
Scale:  2.0
Native: (828.0, 1792.0)

Name:   iPhone XS
Size:   (375.0, 812.0)
Scale:  3.0
Native: (1125.0, 2436.0)

Name:   iPhone XS Max
Size:   (414.0, 896.0)
Scale:  3.0
Native: (1242.0, 2688.0)

翻译:

Xamarin.Essentials 中的 DeviceDisplay.ScreenMetrics 是一个简单的bounds * scale计算(参考:源代码)。

Scale文档明确说明:

默认逻辑坐标空间使用点来测量。

分辨率参考可以看出,XS maxXRPoints测量是完全相同的(尽管像素测量有所差异)。

这就是苹果想让我们使用的简便方法,避免了像Android一样的代码片段化(但已经有3种不同大小的屏幕了...嗯)。

总之,在任何应用程序/代码相关的讨论中,只需参考points(即比例因子),而忘记物理尺寸和像素。


请给我展示一个正确测量 iPhone Xs Max 屏幕渲染像素的例子(结果为 1242 x 2688),以及 iPhone XR 的屏幕渲染像素(结果为 828 x 1792)在代码中的表示方式。目前,我正在使用 Device.Info.PixelScreenSize.Height 和 Device.Info.PixelScreenSize.Width,但仍然得到以下结果: iPhone Xs Max - 1125 x 2436 渲染像素 iPhone XR - 750 x 1624 渲染像素进一步地,我将这些数字分成“渲染于”(它正确返回 Device.Info.ScalingFactor),并获得点数大小: iPhone Xs Max - 375 x 812 点 iPhone XR - 375 x 812 点 - Vegi Woo
1
iPhone XS MAX 的设备日志如下:尺寸:(375.0,812.0) 比例:3.0 本机分辨率:(1125.0,2436.0)``` - Dhaval H. Nena

-1
问题已经解决。实际上,当您从资源文件夹启动应用程序时,XCode 10.0模拟器会选择最合适的图像,并根据其大小构建模拟器的屏幕尺寸。由于早期创建的项目没有新手机尺寸的图像,因此它会选择最大的图像(即iPhone X)。需要进行更正。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接