第二十六篇因为自定item(nav)而使系统右滑返回手势失效的解决方法
Posted 久冬不雨
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第二十六篇因为自定item(nav)而使系统右滑返回手势失效的解决方法相关的知识,希望对你有一定的参考价值。
@interface ViewController () <uigesturerecognizerdelegate> @[email protected] ViewController - (void)viewDidLoad { [super viewDidLoad]; // 自定义返回按钮 UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)]; [button setTitle:@"王俨2" forState:UIControlStateNormal]; [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button]; } - (void)back:(UIButton *)button { [self.navigationController popViewControllerAnimated:YES]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (self.navigationController.viewControllers.count > 1) { // 记录系统返回手势的代理 _delegate = self.navigationController.interactivePopGestureRecognizer.delegate; // 设置系统返回手势的代理为当前控制器 self.navigationController.interactivePopGestureRecognizer.delegate = self; } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // 设置系统返回手势的代理为我们刚进入控制器的时候记录的系统的返回手势代理 self.navigationController.interactivePopGestureRecognizer.delegate = _delegate; } #pragma mark - UIGestureRecognizerDelegate- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { return self.navigationController.childViewControllers.count > 1; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return self.navigationController.viewControllers.count > 1; }@end
以上是关于第二十六篇因为自定item(nav)而使系统右滑返回手势失效的解决方法的主要内容,如果未能解决你的问题,请参考以下文章