统一设置navigation返回和左划手势返回

首先继承UINavigationController的类里面进行书写


///重写push方法 push的控制器隐藏tabbar

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

{

if (self.viewControllers.count > 0) {

viewController.hidesBottomBarWhenPushed = YES;

//1.添加后退按钮

[self addBackButton:viewController];

}

[super pushViewController:viewController animated:animated];

}

//2 自定义后退按钮

- (void)addBackButton:(UIViewController *)viewController {

//开启手势后退

self.interactivePopGestureRecognizer.delegate = (id)self;

//开启手势滑动后退

if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

self.interactivePopGestureRecognizer.enabled = YES;

}

UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:(UIBarButtonItemStyleDone) target:self action:@selector(backClick)];

//间距

UIBarButtonItem *fixed = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

fixed.width = -10;

viewController.navigationItem.leftBarButtonItems =@[fixed,back];

}

//点击后退的时候执行的方法

- (void)backClick {

[self popViewControllerAnimated:YES];

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容