9

I had a look around and didn't find what I was exactly looking for.

Is there a way to get a flip animation when pushing a view controller?

I read that you can change the animation by using a modal view controller but AFAIK the animation for a modal view is from bottom to top and that's not what i am looking for. Is there a way to get a flip animation somehow?

chacha
  • 123
  • 1
  • 1
  • 7

4 Answers4

50

something like this should work

[UIView beginAnimations:@"animation" context:nil];
[self.navigationController pushViewController: yourviewcontroller animated:NO]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
[UIView commitAnimations];

don't forget to set animated to NO when calling pushViewController

John
  • 601
  • 5
  • 8
15

This also works.. for iOS 4.0 and greater

[UIView  transitionWithView:self.navigationController.view duration:0.8  options:UIViewAnimationOptionTransitionFlipFromLeft
                             animations:^(void) {
                                 BOOL oldState = [UIView areAnimationsEnabled];
                                 [UIView setAnimationsEnabled:NO];
                                 [self.navigationController pushViewController:viewController animated:YES];
                                 [UIView setAnimationsEnabled:oldState];
                             }
                             completion:nil];
Hemang
  • 26,840
  • 19
  • 119
  • 186
Kirti Nikam
  • 2,166
  • 2
  • 22
  • 43
  • I doesn’t work well in iOS7, as the view animation is cut in half and then “jumps” into position when animation is done. The discouraged Apple way still works perfectly though. – margusholland Sep 24 '13 at 07:59
4
- (void)viewWillDisappear:(BOOL)animated {
[UIView beginAnimations:@"animation2" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
[UIView commitAnimations]; }

in the new viewcontroller will make it flip back the same way (instead of sliding left) when the back button in the toolbar is pushed -- make sure animation is enabled here, e.g., if you make a custom button to pop the stack, use:

- (void) backToPrevious: (id) sender 
{
    //[self.navigationController popViewControllerAnimated:YES];
    [self dismissModalViewControllerAnimated:YES];
}
Hemang
  • 26,840
  • 19
  • 119
  • 186
Daniel
  • 49
  • 1
  • 1
  • 1
    As mentioned in the [UIView docs](http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html), the `beginAnimations:context:` method is part of a group of methods Apple are discouraging developers from using (from iOS 4 and on). They recommend using UIView's block-based animation methods instead (for example, `animateWithDuration:animations:completion:`). –  Sep 24 '12 at 10:00
1

For modally presented view controllers, you can change the animation with the modalTransitionStyle property. AFAIK, there is no way to change a navigation controller's push animation (except rebuilding UINavigationController from scratch).

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256