解决自定义返回按钮后返回手势失效的问题

  1. 自定义UINavigationController。
@interface JKNavigationController () 
  1. 重构viewDidLoad方法。
  - (void)viewDidLoad { 
        [super viewDidLoad];  
        // 为self创建弱引用对象 
        __weak typeof (self) weakSelf = self; 
        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.interactivePopGestureRecognizer.delegate = weakSelf;
            self.delegate = weakSelf; 
        }
  }
  1. 重构pushViewController方法。
  - (void)pushViewController:(UIViewController *)viewController 
                     animated:(BOOL)animated { 
        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { 
            self.interactivePopGestureRecognizer.enabled = NO; 
        }  
        [super pushViewController:viewController animated:animated];
}
  1. 实现UINavigationControllerDelegate的方法。
  - (void)navigationController:(UINavigationController *)navigationController 
          didShowViewController:(UIViewController *)viewController 
                       animated:(BOOL)animated { 
        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.interactivePopGestureRecognizer.enabled = YES; 
        }
}

你可能感兴趣的:(解决自定义返回按钮后返回手势失效的问题)