How to change the Push and Pop animations in a navigation based app

前端 未结 25 1555
清酒与你
清酒与你 2020-11-22 12:46

I have a navigation based application and I want to change the animation of the push and pop animations. How would I do that?

Edit 2018

Ther

25条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 13:10

    Using iJordan's answer as inspiration, why not simply create a Category on UINavigationController to use throughout your app instead of copying/pasting this animation code all over the place?

    UINavigationController+Animation.h

    @interface UINavigationController (Animation)
    
    - (void) pushViewControllerWithFlip:(UIViewController*) controller;
    
    - (void) popViewControllerWithFlip;
    
    @end
    

    UINavigationController+Animation.m

    @implementation UINavigationController (Animation)
    
    - (void) pushViewControllerWithFlip:(UIViewController *) controller
    {
        [UIView animateWithDuration:0.50
                         animations:^{
                             [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                             [self pushViewController:controller animated:NO];
                             [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
                         }];
    }
    
    - (void) popViewControllerWithFlip
    {
        [UIView animateWithDuration:0.5
                         animations:^{
                             [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                             [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
                         }];
    
        [self popViewControllerAnimated:NO];
    }
    
    @end
    

    Then simply import the UINavigationController+Animation.h file and call it normally:

    [self.navigationController pushViewControllerWithFlip:[[NewViewController alloc] init]];
    
    [self.navigationController popViewControllerWithFlip];
    

提交回复
热议问题