title: ios add constraints for a uiview to a uiscrollview from code
body: <p>In my app i have two top level UIViews i created in IB. One is the UIViewControllers view, it has a subview which is a UIScrollView. The other top level UIView is the content that's going to go in the UIScrollView. That part works fine, i set the UIScrollView's contentsize to the the other UIView's size, and everything works perfectly in portrait mode.
  However if i switch to landscape mode, the UIScrollView resizes nicely, but its subview stays in the top-left corner, but i want it to be in the horizontal center.
  So i created this constraint and added it to the UIScrollView:</p>
  
  <pre><code>  NSLayoutConstraint* iPhoneTextFieldContainerAlwaysInHorizontalCenter = [NSLayoutConstraint
                                                                                  constraintWithItem:self.iPhoneTextFieldContainerView
                                                                                  attribute:NSLayoutAttributeCenterX
                                                                                  relatedBy:NSLayoutRelationEqual
                                                                                  toItem:self.iPhoneMainScrollView
                                                                                  attribute:NSLayoutAttributeCenterX
                                                                                  multiplier:1.0
                                                                              constant:0];
  </code></pre>
  
  <p>However when i switch to landscape mode, the get this constraint exception:</p>
  
  <blockquote>
    <p>(
        NSAutoresizingMaskLayoutConstraint:0x76dacb0 h=-&amp;- v=-&amp;- UIView:0x76d6eb0.width == UIViewControllerWrapperView:0x76d5b10.width,
        NSAutoresizingMaskLayoutConstraint:0x76d7e70 h=--&amp; v=--&amp; UIView:0x76d3110.midX == + 160,
        NSLayoutConstraint:0x76d7030 UIScrollView:0x7680f10.trailing == UIView:0x76d6eb0.trailing,
        NSLayoutConstraint:0x76d6ff0 H:|-(0)-[UIScrollView:0x7680f10] </p>
    
    <p>(Names: '|':UIView:0x76d6eb0 ),
        NSLayoutConstraint:0x76d7330 UIView:0x76d3110.centerX == UIScrollView:0x7680f10.centerX,
        NSAutoresizingMaskLayoutConstraint:0x76deb70 h=-&amp;- v=-&amp;- UIViewControllerWrapperView:0x76d5b10.width ==
    UINavigationTransitionView:0x76d1ab0.width,
        NSAutoresizingMaskLayoutConstraint:0x75a3b60 h=--- v=--- V:[UIWindow:0x91979a0(480)],
        NSAutoresizingMaskLayoutConstraint:0x7595510 h=-&amp;- v=-&amp;- UILayoutContainerView:0x76a5da0.height == UIWindow:0x91979a0.height,
        NSAutoresizingMaskLayoutConstraint:0x759e020 h=-&amp;- v=-&amp;- UINavigationTransitionView:0x76d1ab0.width ==
    UILayoutContainerView:0x76a5da0.width )</p>
    
    <p>Will attempt to recover by breaking constraint 
    NSLayoutConstraint:0x76d7330 UIView:0x76d3110.centerX ==
    UIScrollView:0x7680f10.centerX</p>
  </blockquote>
  
  <p>Can you tell me what i'm doing wrong here?
  Should i remove constraints? Can i do such thing?</p>
  
  <p>Thanks is advance!</p>
  
  <p>Sincerely,</p>
  
  <p>Zoli</p>