Pixel and point
Issue #59
TL;DR: Don’t use nativeScale
and nativeBounds
, unless you’re doing some very low level stuff
What is point and pixel
In iOS there is a distinction between the coordinates you specify in your drawing code and the pixels of the underlying device
The purpose of using points (and the logical coordinate system) is to provide a consistent size of output that is device independent. For most purposes, the actual size of a point is irrelevant. The goal of points is to provide a relatively consistent scale that you can use in your code to specify the size and position of views and rendered content
On a standard-resolution screen, the scale factor is typically 1.0. On a high-resolution screen, the scale factor is typically 2.0
How about scale
and nativeScale
From https://developer.apple.com/documentation/uikit/uiscreen
- var bounds: CGRect: The bounding rectangle of the screen, measured in points.
- var nativeBounds: CGRect: The bounding rectangle of the physical screen, measured in pixels.
- var scale: CGFloat: The natural scale factor associated with the screen.
- var nativeScale: CGFloat: The native scale factor for the physical screen.
The scale factor and display mode
See this for a whole list of devices and their scale factors https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
The iPhone 6 and 6+ introduced display mode https://www.cnet.com/how-to/explaining-display-zoom-on-iphone-6-and-6-plus/
You can see that currently the iPhone 6+, 6s+, 7+ phones have scale factor of 2.88 in zoomed mode, and 2.6 in standard mode
You can also see that in zoomed mode, iPhone 6 has the same logical size as the iPhone 5
Simulator vs device
This is to show you the differences in nativeScale
in simulators and devices in zoomed mode, hence differences in nativeBounds
.
iPhone 6+ simulator
1 | (lldb) po UIScreen.main.scale |
iPhone 6+ device
1 | (lldb) po UIScreen.main.scale |