物理尺寸Iphone XS Max和Iphone XR屏幕[重复]

问题描述 投票:2回答:2

这个问题在这里已有答案:

随着Apple产品系列的更新,我更新了软件,并尝试以像素为单位找出新设备屏幕的物理尺寸。

有了iPhone XS,很清楚:

  • 宽度/高度是1125/2436像素,
  • ScalingFactor 3,
  • 物理上它的宽度/高度为375/812点(如Iphone X)。

随着iPhone XR也很明确:

  • 宽度/高度750/1624像素,
  • ScalingFactor 2,
  • 物理上也产生375/812点高度/宽度。

但是iPhone XS Max并不清楚

  • Apple表示宽度/高度为1242/2688像素,

但是我的计算给出了像iPhone XS这样的数据:

  • 宽度/高度1125/2436像素,
  • ScalingFactor 3,
  • 物理上获得375/812宽度/高度点。

我认为与Device.Info.PixelScreenSize.HeightDevice.Info.PixelScreenSize.Width,我分为Device.Info.ScalingFactor,然后我重新检查Xamarin.Essentials,即DeviceDisplay.ScreenMetrics,然后我也把它分成Device.Info.ScalingFactor

真相在哪里?如何获取可靠的数据?

附:对不起Google翻译

编辑:1。App.cs

 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

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

ios iphone xamarin.forms
2个回答
5
投票

编辑:

我认为你选择了错误的模拟器。 XS Max确实根据您的期望给出了正确的值。下面是一个简单的快速代码(检查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)

原始答案:

DeviceDisplay.ScreenMetricsXamarin.Essentials,是一个简单的bounds * scale计算。 (参考:source code

Scale documentation明确指出:

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

您可以从resolutions参考中看到,XS max和XR的点测量完全相同(尽管像素测量中的差异)。

这就是苹果打算让我们使用的简单方法,并避免像代码中的碎片一样的android(但是已经有3种尺寸...... hmmph)。

总之,对于任何与应用/代码相关的讨论,只需参考点(即比例因子)并忘记物理尺寸和像素。


-1
投票

问题解决了。事实上,当您从Resources文件夹启动应用程序时,XCode 10.0模拟器会获取最合适的图像,并且其大小会构建模拟器的屏幕大小,并且由于之前创建的项目,新手机大小没有图像,它需要最大的(即Iphone X)。需要纠正这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.