title: didAnimateFirstHalfOfRotationToInterfaceOrientation iOS5 replacement
body: <p><code>didAnimateFirstHalfOfRotationToInterfaceOrientation</code> is deprecated in iOS 5.0.  However I would like to use this method in my application. I am using the sample code that Apple offers in the iOS Dev Center, project name <code>AlternateViews</code>. I would like the app to rotate the <code>portraitView</code> while fading in the <code>landscapeView</code>. Can this be done in iOS 5 or is this feature forever gone?</p>
  
  <p><code>portraitView</code> currently calls: </p>
  
  <p><code>[self presentModalViewController:self.landscapeViewController animated:YES];</code></p>
  
  <p>while <code>landscapeView</code> calls this in code in the <code>init</code> method:</p>
  
  <p><code>self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;</code></p>
  
  <p>It appears all of the animation is done in the following PortraitViewController.m:</p>
  
  <pre><code>#import "PortraitViewController.h"
  #import "LandscapeViewController.h"
  
  @implementation PortraitViewController
  
  @synthesize landscapeViewController;
  
  - (void)viewDidLoad
  {
      self.view.backgroundColor = [UIColor colorWithRed:197.0/255.0 green:204.0/255.0 blue:211.0/255.0 alpha:1.0];
  
      LandscapeViewController *viewController = [[LandscapeViewController alloc]
                                                      initWithNibName:@"LandscapeView" bundle:nil];
      self.landscapeViewController = viewController;
      [viewController release];
  
      [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
                                                      name:UIDeviceOrientationDidChangeNotification object:nil];
  }
  
  - (void)viewDidUnload
  {
      self.landscapeViewController = nil;
  }
  
  - (void)dealloc
  {
      [[NSNotificationCenter defaultCenter] removeObserver:self];
      [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
  
      [landscapeViewController release];
  
      [super dealloc];
  }
  
  - (void)orientationChanged:(NSNotification *)notification
  {
      // We must add a delay here, otherwise we'll swap in the new view
      // too quickly and we'll get an animation glitch
      [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
  }
  
  - (void)updateLandscapeView
  {
      UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
      if (UIDeviceOrientationIsLandscape(deviceOrientation) &amp;&amp; !isShowingLandscapeView)
      {
          [self presentModalViewController:self.landscapeViewController animated:YES];
          isShowingLandscapeView = YES;
      }
      else if (deviceOrientation == UIDeviceOrientationPortrait &amp;&amp; isShowingLandscapeView)
      {
          [self dismissModalViewControllerAnimated:YES];
          isShowingLandscapeView = NO;
      }    
  }
  
  // override to allow orientations other than the default portrait orientation
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      return (interfaceOrientation == UIInterfaceOrientationPortrait); // support only portrait
  }
  
  @end
  </code></pre>
  
  <p>Here is my current implementation files which fail miserably.
  PortraitViewController.m:</p>
  
  <pre><code>#import "PortraitViewController.h"
  #import "LandscapeViewController.h"
  
  @implementation PortraitViewController
  
  @synthesize landscapeViewController;
  
  - (void)viewDidLoad
  {   
      LandscapeViewController *viewController = [[LandscapeViewController alloc]
                                                      initWithNibName:@"LandscapeView" bundle:nil];
      self.landscapeViewController = viewController;
      [viewController release];
      NSLog(@"Portrait viewDidLoad");
  }
  
  - (void)viewWillAppear:(BOOL)animated
  {
      [super viewWillAppear:animated];
  
      [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];
  }
  
  - (void)viewDidUnload
  {
      self.landscapeViewController = nil;
  }
  
  - (void)dealloc
  {   
      [landscapeViewController release];
  
      [super dealloc];
  }
  
  - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
      if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
          NSLog(@"Portrait-willAnimateRotationToInterfaceOrientation Portrait");
      } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
          NSLog(@"Portrait-willAnimateRotationToInterfaceOrientation Landscape");
      }
      [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
  
  }
  
  - (void)updateLandscapeView
  {
      UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
      if (UIDeviceOrientationIsLandscape(deviceOrientation) &amp;&amp; !isShowingLandscapeView)
      {
          NSLog(@"Portrait-present Landscape");
          [self presentModalViewController:self.landscapeViewController animated:YES];
          isShowingLandscapeView = YES;
      }
      else if (deviceOrientation == UIDeviceOrientationPortrait &amp;&amp; isShowingLandscapeView)
      {
          NSLog(@"Portrait-dismiss Landscape");
          [self dismissModalViewControllerAnimated:YES];
          isShowingLandscapeView = NO;
      }    
  }
  
  // override to allow orientations other than the default portrait orientation
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
          return NO;
      else
          return YES;
  }
  
  @end
  </code></pre>
  
  <p>LandscapeViewController.m</p>
  
  <pre><code>#import "LandscapeViewController.h"
  
  @implementation LandscapeViewController
  
  // the designated initializer. Override to perform setup that is required before the view is loaded.
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
      if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
      {
          self.wantsFullScreenLayout = YES; // we want to overlap the status bar.
  
          // when presented, we want to display using a cross dissolve
          self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
      }
      return self;
  }
  
  - (void)viewWillAppear:(BOOL)animated
  {
      [super viewWillAppear:animated];
  
      oldStatusBarStyle = [[UIApplication sharedApplication] statusBarStyle];
      [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];
      NSLog(@"Landscape viewWillAppear");
  }
  
  - (void)viewWillDisappear:(BOOL)animated
  {
      [super viewWillDisappear:animated];
  
      [[UIApplication sharedApplication] setStatusBarStyle:oldStatusBarStyle animated:NO];    
  }
  
  // override to allow orientations other than the default portrait orientation
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      // return YES for supported orientations
      if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
          return NO;
      else
          return YES;
      //return UIInterfaceOrientationIsLandscape(interfaceOrientation);
  }
  
  - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
      if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
          NSLog(@"Landscape-willAnimateRotationToInterfaceOrientation Portrait");
          [self dismissModalViewControllerAnimated:YES];
      } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
          NSLog(@"Landscape-willAnimateRotationToInterfaceOrientation Landscape");
  
      }
  }
  
  
  @end
  </code></pre>