title: Autolayout "conflicting constraints"
body: <p>I've created a custom <code>UIView</code> that I use modally to display a <code>UIToolbar</code> and <code>UIPickerView</code>. I'm trying to make it very reusable, so I'm creating all of the UI in code, including setting constraints.</p>
  
  <p>Here's the method body I use to set the view up to be added to another view, and then to animate the controls up onto the view from the bottom.</p>
  
  <p>My view hierarchy is as follows:</p>
  
  <pre><code>"Owner" view (view to which this view is added):&lt;br&gt;
      |--&gt;"Background" view (set to the full size of "Owner", but mainly used as a dimmed background)&lt;br&gt;
          |--&gt;"Container" view (view which holds the toolbar and picker)
              |--&gt; Toolbar
              |--&gt; Picker
  </code></pre>
  
  <p>Here's the code I use to set up the UI:</p>
  
  <pre><code>- (void)prepareForView:(UIView *)view {
      UIView *containerView       = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
      [containerView setTranslatesAutoresizingMaskIntoConstraints:NO];
      self.containerView          = containerView;
  
      UIPickerView *picker        = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 162.0f)];
      [picker setTranslatesAutoresizingMaskIntoConstraints:NO];
      self.picker                 = picker;
  
      UIToolbar *toolbar          = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 44.0f)];
      [toolbar setTranslatesAutoresizingMaskIntoConstraints:NO];
  
      UIBarButtonItem *done       = ...;
      UIBarButtonItem *flexSpace  = ...;
      UIBarButtonItem *cancel     = ...;
      toolbar.items               = @[done, flexSpace, cancel];
  
      [containerView addSubview:picker];
      [containerView addSubview:toolbar];
  
      [containerView addConstraints:[NSLayoutConstraint   constraintsWithVisualFormat:@"|[picker]|"                           options:NSLayoutFormatAlignAllBaseline  metrics:nil views:NSDictionaryOfVariableBindings(picker)]];
      [containerView addConstraints:[NSLayoutConstraint   constraintsWithVisualFormat:@"|[toolbar]|"                          options:NSLayoutFormatAlignAllBaseline  metrics:nil views:NSDictionaryOfVariableBindings(toolbar)]];
      [containerView addConstraints:[NSLayoutConstraint   constraintsWithVisualFormat:@"V:|[toolbar(==44)][picker(==162)]|"   options:NSLayoutFormatAlignAllLeading   metrics:nil views:NSDictionaryOfVariableBindings(toolbar, picker)]];
  
      [containerView layoutIfNeeded];
  
      [self addSubview:containerView];
  
      [self addConstraints:[NSLayoutConstraint            constraintsWithVisualFormat:@"|[containerView]|"                    options:NSLayoutFormatAlignAllBaseline  metrics:nil views:NSDictionaryOfVariableBindings(containerView)]];
      self.containerTop = [NSLayoutConstraint constraintWithItem:containerView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0f constant:self.frame.size.height];
      [self addConstraint:self.containerTop];
  
      [self layoutIfNeeded];
  
  }
  </code></pre>
  
  <p>Basically, I want <code>containerView</code> to be sized according to its contents (which should be a static 206 points). Then, I set a vertical space constraint between its top and the top of its superview (which is <code>self</code>). Later, I animate changing that so that the toolbar and picker "slide up" onto the screen.</p>
  
  <p>Here's the animation code (the error is always triggered BEFORE this point):</p>
  
  <pre><code>// Add the view as a subview
  [view addSubview:self];
  
  // Setup view for display (here's what triggers the message)
  [self prepareForView:view];
  
  // Animate into view
  [UIView animateWithDuration:animated?0.4f:0.0f
                   animations:^{
                       self.alpha = 1.0f;
                   }
                   completion:^(BOOL finished) {
                       // Now, slide the container view in from the bottom of the screen
                       self.containerTop.constant = self.frame.size.height - self.containerView.frame.size.height;
                       [UIView animateWithDuration:animated?0.4f:0.0f
                                        animations:^{
                                            [self layoutIfNeeded];
                                        }
                                        completion:^(BOOL finished) {
                                            if (postDisplay != nil) {
                                                postDisplay();
                                            }
                                        }
                        ];
                   }
   ];
  </code></pre>
  
  <p>This is currently displaying correctly on all simulators and devices in testing, but I hate having warnings/errors, and I'm worried that this might <strong>NOT</strong> work as desired at some point.</p>
  
  <p>Here's the actual error message that's displayed (I'm pretty sure this is exactly the same error every time):</p>
  
  <pre><code>Unable to simultaneously satisfy constraints.
  Probably at least one of the constraints in the following list is one you don't want.
  Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
  (
      "&lt;NSLayoutConstraint:0x170283430 V:|-(0)-[UIToolbar:0x137590850]   (Names: '|':UIView:0x170382b10 )&gt;",
      "&lt;NSLayoutConstraint:0x170283480 V:[UIToolbar:0x137590850(44)]&gt;",
      "&lt;NSLayoutConstraint:0x174084ba0 V:[UIToolbar:0x137590850]-(0)-[UIPickerView:0x137586100]&gt;",
      "&lt;NSLayoutConstraint:0x174081fe0 V:[UIPickerView:0x137586100(162)]&gt;",
      "&lt;NSLayoutConstraint:0x17409bbc0 V:[UIPickerView:0x137586100]-(0)-|   (Names: '|':UIView:0x170382b10 )&gt;",
      "&lt;NSLayoutConstraint:0x174095b80 V:[UIView:0x170382b10(736)]&gt;"
  )
  
  Will attempt to recover by breaking constraint 
  &lt;NSLayoutConstraint:0x174084ba0 V:[UIToolbar:0x137590850]-(0)-[UIPickerView:0x137586100]&gt;
  </code></pre>
  
  <p>What I don't understand is that all of the constraints ARE expected, and then the displayed UI is what I intend. When I inspect the view's layout with <code>po [self.containerView recursiveDescription]</code> in the debugger, I see the frames being exactly what I think they ought to be. Where am I going wrong?</p>