title: IOS6 Constraints using Autolayout
body: <p>I have an app that can be rotated, so I need to deal with portrait and landscape orientations. Additionally, users will be allowed to use pinch gestures to change the scale of views. Here is the basic hierarchy of the views.</p>
  
  <p>mainView is a subview of self.view (from the context of the main view controller). It is a UIImageView, although the image part of it is relatively unimportant. In any case, this is the view within which the rest of the views in this discussion are placed as subviews.</p>
  
  <p>The first is what I call the board. It is the view on which items are assembled by the user. These items are themselves image views.</p>
  
  <p>Additionally, there are what I call palettes. These are simply views that can be resized and scaled by the user. Additionally, the image views just mentioned can be dragged from one palette to another or to the board. The palettes can be thought of as work space for the user. When they are finished their work, they place their assembly onto the board.</p>
  
  <p>So far, I've been working with the app where the board is part of autolayout but the palettes are created programatically as needed. This is good because when the user rotates the device, autolayout automatically places the board appropriately. At least it did until I wanted to add pinch scaling to it.</p>
  
  <p>Autolayout has the following constraints set to it in interface builder:
  Leading, top, trailing, and bottom all set to superview default.</p>
  
  <p>When the user scales the view, the result is that it sort of sticks to the upper-left corner of the screen. I'd rather have it retain the center.</p>
  
  <p>I tried changing this programmatically by adding the following code to the pinch gesture recognizer for this view:</p>
  
  <pre><code>  if (self.pinchView.tag == TAGBOARD) {
       [NSLayoutConstraint constraintWithItem:self.pinchView
                                    attribute:NSLayoutAttributeCenterX
                                    relatedBy:NSLayoutRelationEqual
                                       toItem:self.mainView
                                    attribute:NSLayoutAttributeCenterX
                                   multiplier:1.0
                                     constant:0];
    }
  </code></pre>
  
  <p>but this seemed to do nothing. I'm guessing it's because it conflicts with the IB constraints. Is there something else I can do to make this work with autolayout? Or should I just do it all programmatically like I do with the other views?</p>
  
  <p>In this code example, self.pinchView is the view on which the pinch gesture is applied to. For the sake of this discussion, it is what I've called the board. The self.mainView view is its superview.</p>