iOS UIViewController 简单的切换动画

1.UITabBarController

#import "MyTabBarController.h"

@interface MyTabBarController ()<UITabBarControllerDelegate>

@end

@implementation MyTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.delegate = self;
}

#pragma mark - UITabBarControllerDelegate
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    CATransition* animation = [CATransition animation];
    [animation setDuration:0.5f];
    [animation setType:@"oglFlip"];
    [animation setSubtype:kCATransitionFromRight];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
    [[self.view layer]addAnimation:animation forKey:@"switchView"];
    
    return YES;
}

@end

或者

#pragma mark - UITabBarControllerDelegate
- (nullable id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController
                     animationControllerForTransitionFromViewController:(UIViewController *)fromVC
                                                       toViewController:(UIViewController *)toVC {
    CATransition * animation = [CATransition animation];
    [animation setDuration:0.5];
    [animation setSubtype:kCATransitionFromLeft];
    [animation setType:@"oglFlip"];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [[self.view layer]addAnimation:animation forKey:@"SwitchToView" ];
    
    return nil;
}

2.UINavigationController Push

CATransition* transition =[CATransition animation];
        transition.duration = 0.5;
        transition.type = @"oglFlip";
        transition.subtype = kCATransitionFromLeft;
        
        ViewControllerAAA* two = [ViewControllerAAA new];
        
        [self.navigationController pushViewController:two animated:YES];
        [self.navigationController.view.layer addAnimation:transition forKey:@"abcd"];