1. 程式人生 > >iOS Swift-全域性右滑返回

iOS Swift-全域性右滑返回

1、設定自定義的右滑手勢,別忘記禁止系統右滑手勢

let target = self.interactivePopGestureRecognizer?.delegate
        let pan:UIPanGestureRecognizer = UIPanGestureRecognizer.init(target: target!, action: Selector(("handleNavigationTransition:")))
        self.view.addGestureRecognizer(pan)

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

2、UIGestureRecognizerDelegate代理方法篩選手勢作用條件

設定根控制器右滑手勢不起作用,如果不設定,一旦在根控制器中右滑,將造成app卡死


    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return self.childViewControllers.count > 1
    }

這樣即可