美文网首页
统一设置navigation返回和左划手势返回

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

作者: 淋雨no2 | 来源:发表于2018-08-12 21:15 被阅读0次

首先继承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];

}

相关文章

网友评论

      本文标题:统一设置navigation返回和左划手势返回

      本文链接:https://www.haomeiwen.com/subject/ayptrxtx.html