Search code examples
iphoneiosuinavigationcontrolleruiswipegesturerecognizer

Change navigationcontroll animation


I am woundering if its possible to change the navigation controller animation to something where instead of the new view just sliding onto the view, having the current view slide off as the new view slides on...

I have this function here, which is just detecting my swipes then animating the views like a normal navigationcontroller would do.. but I am hoping I can figure something else out with your help.

// Need to change this to work with viewArray
- (void)swipedScreen:(UISwipeGestureRecognizer*)gesture {

    //Left swipe
    if (gesture.direction == UISwipeGestureRecognizerDirectionLeft) 
    {
        if (viewCount == 0) 
        {     
            viewCount += 1;
            // Load a detial view into the (sub)NavController
            DetailViewControllerA *detailViewA = [[DetailViewControllerA alloc] initWithNibName:@"DetailViewControllerA" bundle:[NSBundle mainBundle]];
            [otherNav pushViewController:detailViewA animated:YES];
        }
    }
    //Right swipe
    else if (gesture.direction == UISwipeGestureRecognizerDirectionRight)
    {
        if (viewCount == 1) 
        {
            viewCount -= 1;
            [self.otherNav popViewControllerAnimated:YES]; 
        }
    }  
}

Solution

  • You can do this with the uiView animation blocks like this one i use to show one blinking UIView

    [UIView animateWithDuration:1.0 
                              delay:0.0 
                            options:UIViewAnimationCurveEaseInOut 
                         animations:^ {
                             self.splash.alpha = 0.2;
                         } 
                         completion:^(BOOL finished) {
                             [UIView animateWithDuration:1.0 animations:^{
                                 self.splash.alpha = 1.0;
                             }];
                         }];
    

    or

    using below code

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.window cache:YES];
        [UIView setAnimationDuration:0.75];
        [UIView setAnimationDelegate:self];
        [self.splash removeFromSuperview];
        [UIView commitAnimations];
    

    for flip transition

    and for changing push/pop animation i use this code

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

    enjoy Codding :)

    Happy Codding :)