title: Changing element left, top, width and height constraints at runtime
body: <p>For the purpose of a framework that I am creating I need to setup UIView objects frame property but while the AutoLayout is on I can't do it. 
  My idea is that I could remove all layout constraints from the UIView object and then creat new ones based on the frame I want it to have.</p>
  
  <p>So this is what I have, but it does not work giving me an error (below).</p>
  
  <pre><code>//Remove current constraints
  [self.view removeConstraints:self.view.constraints];
  
  
  //create x constraint based on new x value
  NSLayoutConstraint *xConstraint =[NSLayoutConstraint
                                     constraintWithItem:self.view
                                     attribute:NSLayoutAttributeLeft
                                     relatedBy:NSLayoutRelationEqual
                                     toItem:self.view.superview
                                     attribute:NSLayoutAttributeLeft
                                     multiplier:1.0
                                     constant:self.x];
  // add new x constrain
  [self.view.superview addConstraint:xConstraint];
  
  //create y constraint based on new y value
  NSLayoutConstraint *yConstraint =[NSLayoutConstraint
                                    constraintWithItem:self.view
                                    attribute:NSLayoutAttributeTop
                                    relatedBy:NSLayoutRelationEqual
                                    toItem:self.view.superview
                                    attribute:NSLayoutAttributeTop
                                    multiplier:1.0
                                    constant:self.y];
  
  [self.view.superview addConstraint:yConstraint];
  
  //create width constraint based on new width value
  NSLayoutConstraint *widthConstraint =[NSLayoutConstraint
                                    constraintWithItem:self.view
                                    attribute:NSLayoutAttributeWidth
                                    relatedBy:NSLayoutRelationEqual
                                    toItem:nil
                                    attribute:NSLayoutAttributeWidth
                                    multiplier:1.0
                                    constant:self.width];
  
  [self.view.superview addConstraint:widthConstraint];
  
  //create height constraint based on new height value
  NSLayoutConstraint *heightConstraint =[NSLayoutConstraint
                                    constraintWithItem:self.view
                                    attribute:NSLayoutAttributeHeight
                                    relatedBy:NSLayoutRelationEqual
                                    toItem:nil
                                    attribute:NSLayoutAttributeHeight
                                    multiplier:1.0
                                    constant:self.height];
  
  [self.view.superview addConstraint:heightConstraint];
  </code></pre>
  
  <p>This is what happens at runtime:</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After changing <code>[self.view addConstraint:heightConstraint];</code> to <code>[self.view.superview addConstraint:heightConstraint];</code> elements display but I am getting the following messages in the console</p>
  
  <p><strong>Error</strong>    </p>
  
  <p>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) </p>
  
  <pre><code>(
      "&lt;NSLayoutConstraint:0x91475c0 H:|-(1)-[UIButton:0x728ab00](LTR)   (Names: '|':UIScrollView:0x72845b0 )&gt;",
      "&lt;NSLayoutConstraint:0x729dad0 H:|-(25)-[UIImageView:0x7284920](LTR)   (Names: '|':UIScrollView:0x72845b0 )&gt;",
      "&lt;NSLayoutConstraint:0x72924d0 UIButton:0x728ab00.leading == UIImageView:0x7284920.leading&gt;"
  )
  </code></pre>