chacha
chacha

Reputation: 123

Flip animation when controller pushed on iPhone

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?

Upvotes: 9

Views: 17637

Answers (4)

Kirti Nikam
Kirti Nikam

Reputation: 2206

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];

Upvotes: 15

Daniel
Daniel

Reputation: 49

- (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];
}

Upvotes: 4

John
John

Reputation: 601

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

Upvotes: 50

Ole Begemann
Ole Begemann

Reputation: 135548

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).

Upvotes: 1

Related Questions