Why there is a difference?
Let's explore some important display characteristics of your iPhone 7:
- a resolution of 750 (W) x 1,334 (H) pixels (16 : 9)
- viewport rez of 375 (W) x 667 (H) pixels (16 : 9)
Because mobile devices with the same screen size can have very different resolutions, developers often use viewports
when they are creating 3D scenes or mobile friendly webpages. In VR and AR fields: the lower resolution is – the quicker a renderer is, and CPU/GPU burden is considerably less. The idea of creating viewports is mainly used for mobile devices. In macOS Screen Resolution
and Viewport Resolution
are identical.
In iPhone, as well as in other mobile devices, Viewport
is a scaled down version (usually 2 or 3 times smaller in each axis) of resolution that allows 3D scenes viewports or websites to be viewed more consistently across different devices and (very important!) with less energy's consumption. Viewports are often more standardized and smaller than resolution sizes.
Snapshots almost always reflect a real screen resolutions:
let screenSize = sceneView.snapshot().size
/* 750 x 1,334 */
/* iPhone 7 rez */
SceneView size often reflects a standardized screen resolution (4 times smaller than specs rez):
let viewportSize = sceneView.bounds.size
/* 375 x 667 */
/* ViewPort rez */
Viewport Rez (1/4) to Screen Rez aspect ratio in iPhone 7:
Schematic depiction!
Viewport size and its real layout in mobile device:
Real depiction!
Additional reference: Phone X
has a ViewPort resolution nine times smaller (375 x 812) than screen resolution (1125 x 2436).
What coordinates are used in Hit-Testing?
In Hit-Testing and Ray-Casting coordinates of ViewPort are used.
Let's make 3 taps using hit-testing method – first tap in a Upper Left corner (near x=0
and y=0
), second tap in center of the screen and third tap in a Lower Right Corner (near x=667
and y=375
):
let point: CGPoint = gestureRecognize.location(in: sceneView)
print(point)
Coordinates of iPhone 7 Viewport is printed in a console:
Quod Erat Demonstrandum!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…