I need to know about _UILayoutGuide
, like what it is, what it does and why it present in the hierarchy of UIView
as a subview
with almost always frame = (0,0,0,0)
.
The safe area layout guide is a property of the UIView class and it inherits from the UILayoutGuide class. It was introduced in iOS 11 and tvOS 11. It helps you correctly position views in a layout. The safe area layout guide replaces the top and bottom layout guides of the UIViewController class.
A layout guide representing the view's margins.
The Content Layout guide relates to the size of the scrollable content area inside the scroll view. The challenging part is to define enough constraints to let Auto Layout calculate the scrollable content area (Content Layout) width and height, which we will go into in the next section.
In Figure 1: You can see constraint to Top Layout Guide and it will take statusbar as a base. Show activity on this post. Go to View Controller in interface Builder. And Click Show the attributes inspector and then Select Status Bar as Defaults Both will be same.
This is a private Apple class, which is used for topLayoutGuide
and bottomLayoutGuide
when auto layout is enabled. If your navigation bar is opaque, one of these "views" will be in [0,0]. If your navigation bars are translucent, same view
will usually be in [0,64] in portrait (20pt for the status bar + 44pt for the navigation bar). There is an analogous one for the bottom toolbar, if you have one.
The reason it is done this way is so you could define layout constraints, which work with UIView
objects.
One thing to notice, if you have some logic which works on subviews, be careful not to include them in your calculations. You can ignore these by testing:
[subview conformsToProtocol:@protocol(UILayoutSupport)]
On iOS 9, there is a new private class, _UILayoutSpacer
, which is not a descendant of UIView
, but can be used to set up constraints. The system seems to work in a dual mode, where controllers loaded from xibs and storyboard still use _UILayoutGuide
, while controllers created in code are set up using _UILayoutSpacer
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With