自定义UINavigationController的返回按钮和动画效果

 1 //UIBarButtonItem 回调方法;
 2 - (void)backToRootVC
 3 {
 4     //跳转到父视图  默认动画效果;
 5     //[self.navigationController popToRootViewControllerAnimated:YES];
 6     
 7     //跳转到父视图  设置动画效果;
 8     [UIView animateWithDuration:1 animations:^{
 9         [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
10         [self.navigationController popViewControllerAnimated:NO];//要取消系统默认动画效果;
11     }];
12 }
13 - (void)viewDidLoad
14 {
15    [super viewDidLoad];
16     
17     /*
18      1:在需要返回的页面,重新定义一个UIBarButtonItem,并把此放到导航条左上角;
19      2:在亲加的UIBarButtonItem里面加一个回调方法,并在回调方法里面POP回上一个页面;
20      3:在pop回上一个页面是加载动画;
21      */
22     
23     self.view.backgroundColor = [UIColor grayColor];
24     self.navigationItem.title = @"grayVC页面";
25     //生成按钮的title为:返回,调用的方法名为:backToRootVC
26     self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(backToRootVC)];
27     
28 }
原文地址:https://www.cnblogs.com/cocoajin/p/3080488.html