title: Changing width of UIView with Autolayout
body: <p>I have made a small demonstration to show what is happening in my app. Basically, I want to animate a UIView on the top left which takes up half of the screen width, to occupy the whole width and "push" the UIView on the top right off screen. Then in a later animation, I want to bring the UIView back on screen and resize the view on the left back to the half screen width it starts out as.</p>
  
  <p>I have taken a few screenshots to demonstrate what happens with the way I have it now.
  This is how it starts out:
  <img src="https://i.stack.imgur.com/LJtyR.png" alt="This is how it starts out on launch">
  Then after resizing the left view
  <img src="https://i.stack.imgur.com/wsLRV.png" alt="This is after enlarging the left UIView">
  After trying to bring it back
  <img src="https://i.stack.imgur.com/5Otzf.png" alt="This is after trying to bring it back to half size">
  And here is the code which changes the size of the views</p>
  
  <pre><code>- (void)replaceWidthConstraintOnView:(UIView *)view withConstant:(float)constant {
  
      [self.view.constraints enumerateObjectsUsingBlock:^(NSLayoutConstraint *constraint, NSUInteger idx, BOOL *stop) {
          if ((constraint.firstItem == view) &amp;&amp; (constraint.firstAttribute == NSLayoutAttributeWidth)) {
              constraint.constant = constant;
          }
      }];
  }
  
  - (IBAction)changeViewSize {
  
  
      CGFloat blueViewWidth = self.blueView.bounds.size.width;
  
      if (blueViewWidth == self.view.bounds.size.width) {
  
          blueViewWidth = blueViewWidth / 2;
          [self replaceWidthConstraintOnView:self.blueView withConstant:blueViewWidth];
  
      }
      else {
          blueViewWidth = blueViewWidth * 2;
          [self replaceWidthConstraintOnView:self.blueView withConstant:blueViewWidth];
      }
  }
  </code></pre>
  
  <p>I am wondering why the blue view doesn't come back to cover only half of the screen. I appreciate any help!</p>