title: Update constraints after superview frame dimensions change
body: <p>I have a very simple <code>UIViewController</code> that I am using to try to better understand constraints, auto layout, and frames. The view controller has two subviews: both are <code>UIView</code>s that are intended to either sit side-by-side or top/bottom depending on the device orientation. Within each <code>UIView</code>, there exists a single label that should be centered within its superview. </p>
  
  <p>When the device is rotated, the <code>UIView</code>s update correctly. I am calculating their frame dimensions and origins. However, the labels do not stay centered and they do not respect the constraints defined in the storyboard.</p>
  
  <p>Here are screenshots to show the issue. If I comment out the <code>viewDidLayoutSubviews</code> method, the labels are perfectly centered (but then the <code>UIView</code>s are not of the correct size). I realize that I could manually adjust the frame for each of the labels, but I am looking for a way to make them respect their constraints within the newly resized superviews.
  <img src="https://i.stack.imgur.com/3rrs0.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/nr90O.png" alt="enter image description here">
  Here is the code:</p>
  
  <pre><code>#import "ViewController.h"
  
  @interface ViewController ()
  @property (nonatomic) CGFloat spacer;
  @end
  
  @implementation ViewController
  
  @synthesize topLeftView, bottomRightView, topLeftLabel, bottomRightLabel;
  
  - (void)viewDidLoad {
      [super viewDidLoad];
  
      topLeftLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
      bottomRightLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  
      self.spacer = 8.0f;
  }
  
  - (void)viewDidLayoutSubviews
  {
      if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
          [self setupTopLeftForLandscape];
          [self setupBottomRightForLandscape];
      } else {
          [self setupTopLeftForPortrait];
          [self setupBottomRightForPortrait];
      }
  
  }
  
  - (void) setupTopLeftForPortrait {
      CGRect frame = topLeftView.frame;
      frame.origin.x = self.spacer;
      frame.origin.y = self.spacer;
      frame.size.width = self.view.frame.size.width - 2*self.spacer;
      frame.size.height = (self.view.frame.size.height - 3*self.spacer) * 0.5;
      [topLeftView setFrame:frame];
  }
  
  - (void) setupBottomRightForPortrait {
      CGRect frame = bottomRightView.frame;
      frame.origin.x = self.spacer;
      frame.origin.y = topLeftView.frame.size.height + 2*self.spacer;
      frame.size.width = topLeftView.frame.size.width;
      frame.size.height = topLeftView.frame.size.height;
      [bottomRightView setFrame:frame];
  }
  
  - (void) setupTopLeftForLandscape {
      CGRect frame = topLeftView.frame;
      frame.origin.x = self.spacer;
      frame.origin.y = self.spacer;
      frame.size.width = (self.view.frame.size.width - 3*self.spacer) * 0.5;
      frame.size.height = self.view.frame.size.height - 2*self.spacer;
      [topLeftView setFrame:frame];
  }
  
  - (void) setupBottomRightForLandscape {
      CGRect frame = bottomRightView.frame;
      frame.origin.x = self.topLeftView.frame.size.width + 2*self.spacer;
      frame.origin.y = self.spacer;
      frame.size.width = topLeftView.frame.size.width;
      frame.size.height = topLeftView.frame.size.height;
      [bottomRightView setFrame:frame];
  }
  
  @end
  </code></pre>