Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom topLayoutGuide length in container view controller

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!

like image 399
Accatyyc Avatar asked Jan 30 '14 09:01

Accatyyc


People also ask

How does a container view controller manage a view?

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.

What are container view controllers in UIKit?

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.

What is master detail in uisplitviewcontroller?

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.

What is the difference between tab bar and container view controllers?

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.


1 Answers

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.

like image 181
petehare Avatar answered Nov 12 '22 06:11

petehare