Push ViewController with modal animation (horizontal flip)

stackOverFlew picture stackOverFlew · Feb 10, 2013 · Viewed 9.2k times · Source

I need to push a view controller to another view controller.

menuVC -> VC1 ->VC2

going from menuVC to VC1 requires no animation, but going from VC1 to VC2 and from VC2 to VC1 requires the flip animaton to occur.

However, when going from VC2 to menuVC, no animation is needed.

I am using the following code:

(from how to push a viewController with flip animation)

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
FlashCardVC *flashCardVC = [[FlashCardVC alloc] init];
[self.navigationController pushViewController:flashCardVC animated:NO];
[UIView commitAnimations];

The screen goes completely blank when I try and do the above.

What is wrong?

Answer

rdelmar picture rdelmar · Feb 10, 2013

You really should be using block based animations now. Also, if you're instantiating a storyboard controller from a controller that's also in the same storyboard, you can more easily access that storyboard with self.storyboard.

-(IBAction)flipToNext:(id)sender {
    SecondController *next = [self.storyboard instantiateViewControllerWithIdentifier:@"Next"];
    [self.navigationController pushViewController:next animated:NO];
    [UIView transitionWithView:self.navigationController.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:nil];
}