Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController custom transition animation on Back button

I made a custom transition in UINavigationController, code I used:

SecondView *newView = [[SecondView alloc] initWithNibName:nil bundle:nil];
[UIView beginAnimtaions:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown];
[self.navigationcontroller pushViewController:newView animated:NO];
[UIView commitAntimations];
[newView release];

But that transition animation applies only on Forward, can I apply it on Back?

Thanks

like image 762
Houranis Avatar asked Dec 22 '22 10:12

Houranis


1 Answers

Of course, simply define a custom UIBarButtonItem for back button and link it to a custom method that do something similar you do to push the controller, but instead of pushing you'll need to pop the view controller.

i.e. first you create your back button (in init or viewDidLoad method)

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(back)];
self.navigationItem.leftBarButtonItem = backBarButtonItem;
[backBarButtonItem release];

then, in your back method, you can do your custom animation

-(IBAction)back {

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration: 1.0];

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:YES];

    [[self navigationController] popViewControllerAnimated:NO];

    [UIView commitAnimations];


}
like image 102
Manlio Avatar answered May 20 '23 01:05

Manlio