title: Objective C: Orientation Change With UIScrollview
body: <p>I am trying to make an app with UIScrollView (pagingEnabled) that should adapt on the device's interface orientation.</p>
  
  <p>to do this, i made two UIScrollViews loaded with UIImageviews and UIButtons inside and animations (CA). one for portrait and the other one for landscape (you'll see it in my code).</p>
  
  <p>now my problem is whenever i rotate the device, yes! it respond to the orientation change but it goes back to the first page.</p>
  
  <p>ok picture this... you are already on the 10th page of the scrollView in portrait then when you switched to landscape it is on the first page again.</p>
  
  <p>i hope explained it clearly.</p>
  
  <p>and... it crashes on iPad when i rotate it.</p>
  
  <pre><code>- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
  }
  
  - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
      [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
      if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
          //self.view = portraitView;
          [self changeTheViewToPortrait:YES andDuration:duration];
  
      }
      else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
          //self.view = landscapeView;
          [self changeTheViewToPortrait:NO andDuration:duration];
      }
  }
  
  - (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{
  
      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationDuration:duration];
  
      if(portrait){
          //change the view and subview frames for the portrait view
          [self forPortrait];
          [self removeMainSVLContents];
      }
      else{   
          //change the view and subview  frames for the landscape view
          [self forLandscape];
          [self removeMainSVPContents];
      }
  
      [UIView commitAnimations];
  }
  </code></pre>
  
  <p>What's inside "forPortrait" is the same as in "forLandscape" they just have different frames  and it has different images too that will fit the screen on portrait and landscape.</p>