Search code examples
iphoneiosanimationuinavigationcontroller

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!


Solution

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