17
votes

Say for example, I have made a custom container view controller resembling a UINavigationController, but it has 2 navigation bars in the top.

Then, in child view controllers I use autolayout, and I of course want content to begin below the second navigation bar.

To achieve this automatically, I need to set the top layout guide to the height of the two navigation bars combined.

I assumed that we could just override the topLayoutGuide-property, but whatever I do, the topLayoutGuide function never gets called in either my custom container view controllers or the child view controllers.

So this means that topLayoutGuide is basically a worthless property, working ONLY with Apple's own container view controllers?

Please tell me I'm wrong!

1

1 Answers

7
votes

Reading through the docs on this, the topLayoutGuide property is (readonly), and it's length attribute is also (readonly). In addition to that, it states:

A view controller within a container view controller does not set this property's value. Instead, the container view controller constrains the value to indicate:

  • The bottom of the navigation bar, if a navigation bar is visible
  • The bottom of the status bar, if only a status bar is visible
  • The top edge of the view controller’s view, if neither a status bar nor navigation bar is visible

Those three scenarios imply to me that it's probably not customizable, although I'd love to be proved wrong. Seems like a great use case for this functionality.