自定义导航控制器返回按钮
在viewController的基类viewDidLoad中添加自定义返回按钮
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
[button setTitle:@"返回" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
if (self.navigationController.childViewControllers.count > 1) {
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
}
在viewWillAppear中设置系统手势动画的代理
if (self.navigationController.childViewControllers.count > 1) {
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
并实现代理方法(利用此方法禁用导航控制器跟控制器的返回手势)
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
if (self.navigationController.childViewControllers.count > 1) {
return YES;
}
return NO;
}