What is _UILayoutGuide?

前端 未结 3 1447
感动是毒
感动是毒 2020-12-31 10:06

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 alm

3条回答
  •  佛祖请我去吃肉
    2020-12-31 10:27

    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.

提交回复
热议问题