Swift4.0 侧滑手势返回上个界面

1.0 OC的写法

1.0.1首先自定义一个UINavigationController,在viewDidLoad中写下面的代码就完成了

   typeof (self) weakSelf = self;
   if ([self  respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
       self.interactivePopGestureRecognizer.delegate = weakSelf;
       self.delegate = weakSelf;
   }

1.1 Swift的写法很简单同OC也要自定义UINavigationController在viewDidLoad中写

    let isTrue = self.navigationController?.responds(to: #selector(getter: interactivePopGestureRecognizer));
    var isMore:Int = 0;
    if ((self.navigationController?.viewControllers.count) != nil) {
        isMore = (self.navigationController?.viewControllers.count)!;
    }
    if isMore > 1 {
        if isTrue! {
            self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true;
        }else{
            self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false;
        }
    }else{
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false;
    }

喜欢点个关注!!!

你可能感兴趣的:(Swift4.0 侧滑手势返回上个界面)