topLayoutGuide in child view controller

前端 未结 11 2046
既然无缘
既然无缘 2020-12-07 11:29

I have a UIPageViewController with translucent status bar and navigation bar. Its topLayoutGuide is 64 pixels, as expected.

However, the ch

11条回答
  •  独厮守ぢ
    2020-12-07 12:11

    I think the guides are definitely meant to be set for nested child controllers. For example, suppose you have:

    • A 100x50 screen, with a 20 pixel status bar at the top.
    • A top-level view controller, covering the whole window. Its topLayoutGuide is 20.
    • A nested view controller inside the top view covering the bottom 95 pixels, eg. 5 pixels down from the top of the screen. This view should have a topLayoutGuide of 15, since its top 15 pixels are covered by the status bar.

    That would make sense: it means that the nested view controller can set constraints to prevent unwanted overlap, just like a top-level one. It doesn't have to care that it's nested, or where on the screen its parent is displaying it, and the parent view controller doesn't need to know how the child wants to interact with the status bar.

    That also seems to be what the documentation--or some of the documentation, at least--says:

    The top layout guide indicates the distance, in points, between the top of a view controller’s view and the bottom of the bottommost bar that overlays the view

    (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UILayoutSupport_Protocol/Reference/Reference.html)

    That doesn't say anything about only working for top-level view controllers.

    But, I don't know if this is what actually happens. I've definitely seen child view controllers with nonzero topLayoutGuides, but I'm still figuring out the quirks. (In my case the top guide should be zero, since the view isn't at the top of the screen, which is what I'm banging my head against at the moment...)

提交回复
热议问题