首先繼承UINavigationController的類(lèi)里面進(jìn)行書(shū)寫(xiě)
///重寫(xiě)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 {
//開(kāi)啟手勢(shì)后退
self.interactivePopGestureRecognizer.delegate = (id)self;
//開(kāi)啟手勢(shì)滑動(dòng)后退
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];
}
//點(diǎn)擊后退的時(shí)候執(zhí)行的方法
- (void)backClick {
[self popViewControllerAnimated:YES];
}