iOS 全屏手勢返回程式碼實現

記憶有你發表於2016-02-01


/// 啟用手勢返回

    func enableGesturePop(gestureDelegate: UIGestureRecognizerDelegate, interactiveEnable: Bool, navigationViewEnable: Bool) {

        let target = self.interactivePopGestureRecognizer?.delegate

        

        let panGesture = UIPanGestureRecognizer(target: target, action: "handleNavigationTransition:")

        panGesture.delegate = gestureDelegate

        if navigationViewEnable {

            self.view.addGestureRecognizer(panGesture)

        } else {

            let control = self.viewControllers.last

            control?.view.addGestureRecognizer(panGesture)

        }

        

        self.interactivePopGestureRecognizer?.enabled = interactiveEnable

    }

    

    /// 啟用手勢返回

    func enableGesturePop(gestureDelegate: UIGestureRecognizerDelegate) {

        enableGesturePop(gestureDelegate, interactiveEnable: true, navigationViewEnable: false)

    }


UIGestureRecognizerDelegate 委託來自控制器,用於控制該類是否啟用手勢返回

相關文章