I want to mention something that caught me first when I was trying to adapt a SpriteKit-based app to avoid the round edges and "notch" of the new iPhone X, as suggested by the latest Human Interface Guidelines: The new property safeAreaLayoutGuide
of UIView
needs to be queried after the view has been added to the hierarchy (for example, on -viewDidAppear:
) in order to report a meaningful layout frame (otherwise, it just returns the full screen size).
From the property's documentation:
The layout guide representing the portion of your view that is unobscured by bars and other content. When the view is visible onscreen, this guide reflects the portion of the view that is not covered by navigation bars, tab bars, toolbars, and other ancestor views. (In tvOS, the safe area reflects the area not covered the screen's bezel.) If the view is not currently installed in a view hierarchy, or is not yet visible onscreen, the layout guide edges are equal to the edges of the view.
(emphasis mine)
If you read it as early as -viewDidLoad:
, the layoutFrame
of the guide will be {{0, 0}, {375, 812}}
instead of the expected {{0, 44}, {375, 734}}