美文网首页iOS菜鸟食谱
解决自定义返回按钮后返回手势失效的问题

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

作者: 火鸟先生 | 来源:发表于2015-09-29 10:20 被阅读157次
    1. 自定义UINavigationController。
    @interface JKNavigationController () <UINavigationControllerDelegate, UIGestureRecognizerDelegate>
    
    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; 
            }
    }
    

    相关文章

      网友评论

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

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