Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController: pop view controller in the opposite direction

I'm trying to call [[self navigationController] popViewControllerAnimated:YES] but making the animation slide right to left instead of left to right. Any easy way to do this? I want to return to the previous view. Any help is appreciated. Thanks!

like image 510
Mason Avatar asked Nov 06 '11 22:11

Mason


2 Answers

This is how one can pop view controller in opposite direction. Its working for me 100%

CATransition *transition = [CATransition animation];
    transition.duration = 0.45;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
    transition.type = kCATransitionFromRight;
    [transition setType:kCATransitionPush];
    transition.subtype = kCATransitionFromRight;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    [self.navigationController popViewControllerAnimated:NO];
like image 105
NightFury Avatar answered Nov 02 '22 06:11

NightFury


It is possible, look at the following code I used a while back and try to make it work for yourself. Yu only need to change the setAnimationTransition

[UIView  beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];

There are a few different kind of default animations to use, apples site says this kind of animations are possible:

typedef enum {
   UIViewAnimationTransitionNone,
   UIViewAnimationTransitionFlipFromLeft,
   UIViewAnimationTransitionFlipFromRight,
   UIViewAnimationTransitionCurlUp,
   UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;

So in your case you would want to use the following:

    [UIView  beginAnimations:nil context:nil];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    [self.navigationController popViewControllerAnimated:NO];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
    [UIView commitAnimations];
like image 34
Wesley Avatar answered Nov 02 '22 08:11

Wesley