UINavigation处理某些ViewController的特定向后滑动

时间:2019-05-03 02:35:58

标签: ios swift uinavigationcontroller interactivepopgesture

在当前项目中,我使用一个主要的UINavigationController,并且已推送了要显示的每个控制器。另外,我已从UINavigationController的默认用户体验启用弹出手势,当我在屏幕左侧滑动时,它将弹出我的视图控制器,并且一切正常。

self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
self.navigationController?.interactivePopGestureRecognizer?.delegate = self

extension MyCustomViewController: UIGestureRecognizerDelegate{
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return gestureRecognizer.isKind(of: UIScreenEdgePanGestureRecognizer.self)
    }
}

但是在某些情况下,我在滑动ViewController时需要处理特定的操作。我要使用此功能,而不是弹出ViewController:

extension UINavigationController {
    func backToViewController(vc: Swift.AnyClass) {
        for element in viewControllers as Array {
            if element.isKind(of: vc) {
                self.popToViewController(element, animated: true)
                break
            }
        }   
    }
}

0 个答案:

没有答案