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

前端 未结 25 1154
清酒与你
清酒与你 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:24

    Realising this is an old question. I still would like to post this answer, as I had some problems popping several viewControllers with the proposed answers. My solution is to subclass UINavigationController and override all the pop and push methods.

    FlippingNavigationController.h

    @interface FlippingNavigationController : UINavigationController
    
    @end
    

    FlippingNavigationController.m:

    #import "FlippingNavigationController.h"
    
    #define FLIP_DURATION 0.5
    
    @implementation FlippingNavigationController
    
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        [UIView transitionWithView:self.view
                          duration:animated?FLIP_DURATION:0
                           options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionTransitionFlipFromRight
                        animations:^{ [super pushViewController:viewController
                                                       animated:NO]; }
                        completion:nil];
    }
    
    - (UIViewController *)popViewControllerAnimated:(BOOL)animated
    {
        return [[self popToViewController:[self.viewControllers[self.viewControllers.count - 2]]
                                 animated:animated] lastObject];
    }
    
    - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
    {
        return [self popToViewController:[self.viewControllers firstObject]
                                animated:animated];
    }
    
    - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        __block NSArray* viewControllers = nil;
    
        [UIView transitionWithView:self.view
                          duration:animated?FLIP_DURATION:0
                           options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionTransitionFlipFromLeft
                        animations:^{ viewControllers = [super popToViewController:viewController animated:NO]; }
                        completion:nil];
    
        return viewControllers;
    }
    
    @end
    
    0 讨论(0)
提交回复
热议问题