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!
A container view controller manages a view just like any other UIViewController subclass. In addition to managing a view, a container view controller also manages one or more child view controllers. It acts as the parent view controller of one or more child view controllers.
As I mentioned earlier, UIKit includes a number of UIViewController subclasses that are container view controllers, such as UINavigationController, UITabBarController, and UISplitViewController. Each of these classes implements a navigation paradigm that is commonly found in iOS applications.
A UISplitViewController object displays the content of two view controllers in a master-detail arrangement. In this arrangement, the content of one view controller (the master) determines what details are displayed by the other view controller.
A tab bar controller is aware of its child view controllers, but it doesn't know or care about their type or function. All it knows is how to manage them and navigate between them. A key advantage of container view controllers is reusability.
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.
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