title: Views moved out of place when rotating
body: <p>I created a UIViewController (based on <a href="https://stackoverflow.com/questions/2267117/how-to-switch-views-when-rotating">How to switch views when rotating</a>) to switch between 2 views when the device rotates. Each view is "specialized" for a particular orientation.</p>
  
  <p>It uses the UIDeviceOrientationDidChangeNotification notification to switch views:</p>
  
  <pre><code>-(void) deviceDidRotate: (NSNotification *) aNotification{
  
      UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
  
      NSLog(@"Device rotated to %d!", orientation);
  
      if ((orientation == UIDeviceOrientationPortrait) ||
          (orientation == UIDeviceOrientationPortraitUpsideDown)) {
          [self displayView:self.portraitViewController.view];
      }else if ((orientation == UIDeviceOrientationLandscapeLeft) ||
                 (orientation == UIDeviceOrientationLandscapeRight)) {
          [self displayView:self.landscapeViewController.view];
      }
  
  }
  </code></pre>
  
  <p>and sort of works.  The problems shows up when I rotate to Landscape and then back to Portrait. When going back to portrait the subviews aren't displayed in the right place, specially the UIPickerView:</p>
  
  <p><strong>First Time Portrait</strong>:
  <img src="https://i.stack.imgur.com/k7REc.png" alt="enter image description here"></p>
  
  <p><strong>Rotate to Landscape</strong>:
  <img src="https://i.stack.imgur.com/4WNUx.png" alt="enter image description here"></p>
  
  <p><strong>Back to Portrait</strong>:
  <img src="https://i.stack.imgur.com/N2qv0.png" alt="enter image description here"></p>
  
  <p>If I repeat the rotation process, things just get worse. What am I doing wrong?</p>
  
  <p>The source code is here: <a href="http://dl.dropbox.com/u/3978473/forums/Rotator.zip" rel="nofollow noreferrer">http://dl.dropbox.com/u/3978473/forums/Rotator.zip</a></p>
  
  <p>Thanks in advance!</p>