3

With the update of the Apple product line, I updated the software and tried to find out the physical size of the screens of the new devices in pixels.

With the iPhone XS it's clear:

  • the width / height is 1125 / 2436 pix,
  • ScalingFactor 3,
  • physically it's 375 / 812 points in width / height (like Iphone X).

With the iPhone XR is also clear:

  • the width / height of 750 / 1624 pix,
  • ScalingFactor 2,
  • physically also produces 375 / 812 points in height / width.

But it's not clear with the iPhone XS Max

  • Apple indicates a width / height of 1242 / 2688 pixels,

but my calculations give data like the iPhone XS:

  • width / height 1125 / 2436 pix,
  • ScalingFactor 3,
  • physically get 375/ 812 width / height points.

I think with Device.Info.PixelScreenSize.Height and Device.Info.PixelScreenSize.Width, I divide into Device.Info.ScalingFactor, then I recheck Xamarin.Essentials, namely DeviceDisplay.ScreenMetrics, then I also divide it into Device.Info.ScalingFactor.

Where is the truth? What to take for reliable data?

P.S. Sorry for Google Translate

EDIT: 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

Vegi Woo
  • 65
  • 1
  • 6
  • May be this could help : https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions – Swapnil Luktuke Sep 20 '18 at 11:39
  • Yes, everything is shown perfectly and correctly here, I agree with that. But why does not Device.Info.PixelScreenSize and DeviceDisplay.ScreenMetrics malfunction this show? – Vegi Woo Sep 20 '18 at 11:45

2 Answers2

8

EDIT :

I think you have wrong simulator selected. The XS Max does give correct values as per your expectation. Heres a simple swift code (check nativeBounds for actual size) :

    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)")

And heres the output from all four X simulators

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)

Original answer :

DeviceDisplay.ScreenMetrics in Xamarin.Essentials, is a simple bounds * scale calculation. (Ref : source code)

Scale documentation clearly states :

The default logical coordinate space is measured using points.

You can see from resolutions reference, that Points measurement for XS max and XR is exactly the same (although theres difference in pixel measurement).

This is what apple intends us to use for simplicity and avoid android like fragmentation in code (but theres 3 sizes already .. hmmph).

In conclusion, for any app / code related discussion, just refer to the points (i.e. scale factor) and forget physical dimensions and pixels.

Swapnil Luktuke
  • 10,385
  • 2
  • 35
  • 58
  • Please show me an example of the correct measurement of the iPhone Xs Max screen in Rendered Pixels (with the result 1242 at 2688) and the iPhone XR (with the result 828 at 1792) in the code. At the moment I'm using Device.Info.PixelScreenSize.Height and Device.Info.PixelScreenSize.Width, and I still get the result: iPhone Xs Max - 1125 at 2436 Rendered Pixels iPhone XR - 750 at 1624 Rendered Pixels Further I divide these digits into "render at" (it correctly returns Device.Info.ScalingFactor) and get the sizes in points: iPhone Xs Max - 375 for 812 Points iPhone XR - 375 at 812 Points – Vegi Woo Sep 20 '18 at 13:31
  • 1
    Device log for iPhone XS MAX is as below ```Name: iPhone XS Max Size: (375.0, 812.0) Scale: 3.0 Native: (1125.0, 2436.0) ``` – Dhaval H. Nena Aug 26 '19 at 14:48
-1

The question is settled. In fact, the XCode 10.0 simulator when you start the application from the Resources folder takes the most appropriate image and by its size builds the screen size of the simulator, and since the projects created earlier, there are no images for the new phone sizes, it takes the largest (that is, for the Iphone X). It is required to correct this.

Vegi Woo
  • 65
  • 1
  • 6