title: Custom iOS interface orientation change animation with OpenGL
body: <p>I have an iPad app and am drawing the main view with openGL and I want to animate my own change when the device is rotated. </p>
  
  <p>Note that this app only draws occasionally, it is not constantly animating. Also my scene is a (very complex) 2D drawing, not 3D. I just want it to simply rotate around the display center during device orientation change, maintaining correct aspect ratio.</p>
  
  <p>At the moment I just have the following code:</p>
  
  <pre><code>- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
      // nothing yet
  }
  
  - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  {
      IMMainView *mv = (IMMainView *)self.view;
      [mv createRenderbuffer];
      [mv drawView];
  }
  </code></pre>
  
  <p>I just re-create the OpenGL render buffer to match the new width and height once the rotation completes.</p>
  
  <p>The default iOS behavior seems to rotate the view but also stretches it weirdly as the aspect ratio changes.</p>
  
  <p>I can animate my drawing parameters to make something better appear during the transition, but I don't understand (1) how to stop iOS animating my layer and (2) how to set up an animation loop from these method calls that matches the iOS animation.</p>
  
  <p>For example, during the animation, are the actual view width and height being changed progressively?</p>
  
  <p>Also a possibly issue is the question of when to re-create the render buffer, because if the OpenGL buffer does not match the iOS view bounds then the pixel aspect ratios are not right and the drawing looks bad.</p>
  
  <p>Any help would be appreciated.</p>