随着苹果产品线的更新,我更新了软件并试图找出新设备屏幕的物理尺寸(像素)。
对于 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。
真相在哪里?应该采取什么数据才可靠?
附:抱歉使用了谷歌翻译。
2. AppDelegate.cs(应用程序代理)
3. MainPageViewModel.cs (这是一个C#文件名)
对于 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;
}
}