title: How to set topLayoutGuide position for child view controller
body: <p>I'm implementing a custom container which is pretty similar to UINavigationController except for it does not hold the whole controller stack. It has a UINavigationBar which is constrained to the container controller's topLayoutGuide, which happens to be 20px off the top, which is OK. </p>
  
  <p>When I add a child view controller and put its view into the hierarchy I want its topLayoutGuide seen in IB and used for laying out the child view controller's view's subviews to appear at the bottom of my navigation bar. There is a note of what is to be done in the relevant documentation:</p>
  
  <blockquote>
    <p>The value of this property is, specifically, the value of the length
    property of the object returned when you query this property. This
    value is constrained by either the view controller or by its enclosing
    container view controller (such as a navigation or tab bar
    controller), as follows:</p>
    
    <ul>
    <li>A view controller not within a container view controller constrains    this property to indicate the bottom of the status bar, if visible,<br>
    or else to indicate the top edge of the view controller's view. </li>
    <li>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: 
    <ul>
    <li>The bottom of the navigation bar, if a    navigation bar is visible </li>
    <li>The bottom of the status bar, if only a    status bar is visible </li>
    <li>The top edge of the view controller’s view, if    neither a status bar nor navigation bar is visible</li>
    </ul></li>
    </ul>
  </blockquote>
  
  <p>But I don't quite understand how to "constrain it's value" since both the topLayoutGuide and it's length properties are readonly.</p>
  
  <p>I've tried this code for adding a child view controller:</p>
  
  <pre><code>[self addChildViewController:gamePhaseController];
  UIView *gamePhaseControllerView = gamePhaseController.view;
  gamePhaseControllerView.translatesAutoresizingMaskIntoConstraints = NO;
  [self.contentContainer addSubview:gamePhaseControllerView];
  
  NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[gamePhaseControllerView]-0-|"
                                                                           options:0
                                                                           metrics:nil
                                                                             views:NSDictionaryOfVariableBindings(gamePhaseControllerView)];
  
  NSLayoutConstraint *topLayoutGuideConstraint = [NSLayoutConstraint constraintWithItem:gamePhaseController.topLayoutGuide
                                                                              attribute:NSLayoutAttributeTop
                                                                              relatedBy:NSLayoutRelationEqual
                                                                                 toItem:self.navigationBar
                                                                              attribute:NSLayoutAttributeBottom
                                                                             multiplier:1 constant:0];
  NSLayoutConstraint *bottomLayoutGuideConstraint = [NSLayoutConstraint constraintWithItem:gamePhaseController.bottomLayoutGuide
                                                                                 attribute:NSLayoutAttributeBottom
                                                                                 relatedBy:NSLayoutRelationEqual
                                                                                    toItem:self.bottomLayoutGuide
                                                                                 attribute:NSLayoutAttributeTop
                                                                                multiplier:1 constant:0];
  [self.view addConstraint:topLayoutGuideConstraint];
  [self.view addConstraint:bottomLayoutGuideConstraint];
  [self.contentContainer addConstraints:horizontalConstraints];
  [gamePhaseController didMoveToParentViewController:self];
  
  _contentController = gamePhaseController;
  </code></pre>
  
  <p>In the IB I specify "Under Top Bars" and "Under Bottom Bars" for the gamePhaseController. One of the views is specifically constrained to the top layout guide, anyway on the device it appears to be 20px off the the bottom of the container's navigation bar...</p>
  
  <p>What is the right way of implementing a custom container controller with this behavior?</p>