iOS - View not loading properly in iPad when rotating

I have created a simple iPad application with rotation support. It has two view controllers. First View Controller is loaded automatically as rootViewController of the AppDelegate. It has a button on it which, when clicked, changes the rootViewController of AppDelegate to Second View Controller. The Second View Controller has a button on it which sets rootViewController back to First View Controller. This work Perfectly in Portrait mode. But when I rotate the simulator to Landscape mode, and click on the button on First View Controller to load the Second View Controller, it first displays the Second View according to the device (un-rotated), and then rotates the display to normal (Landscape), after completing the animation. What is going wrong ? The methods in AppDelegate to set View Controllers are as follows:

(void)loadSecondView 
{
    SecondView *secondViewController = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.window cache:YES ];    
    self.window.rootViewController = secondViewController;
    [UIView commitAnimations];     
}


(void) removeSecondView 
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.window cache:YES ];
    self.window.rootViewController = self.firstViewController;
    [UIView commitAnimations];    
}

Answers


Basically you're wrapping two operations inside an animation block.

  1. making a new view controller as the root view
  2. showing that view in a curl animation

As a result, you see two operations during your animation.

  1. new view is added to the window, and it's rotated based on device's orientation
  2. curl animation makes the new view visible

You can fix this problem by applying the following change:

- (void)loadSecondView {
    SecondView *secondview = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
    self.window.rootViewController = secondview;
    self.window.rootViewController.view.hidden = YES;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.window cache:YES ];    
    self.window.rootViewController.view.hidden = NO;
    [UIView commitAnimations];
}

- (void)removeSecondView {
    self.window.rootViewController = self.viewController;
    self.window.rootViewController.view.hidden = YES;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.window cache:YES ];
    self.window.rootViewController.view.hidden = NO;
    [UIView commitAnimations];
}

Basically, we're adding the view without any animation effect, and for transition animation, we're using view's hidden property.

HTH.


Need Your Help

Any way to compute statistics on a hive table for all partitions with a single analyze command?

hadoop hive table-statistics

The syntax I see for computing statistics in hive seems to indicate the answer to the title question would be 'no':

css :after content not underlined

css pseudo-class underline text-decorations css-content

To seperate the links in navigation I have set the following