1
votes

I found that using navigation controller, the default back swipe gesture will be introduced when user swipes from the left side of the screen, which will make the app go back to the previous view.

Is there a way to start from any point on the screen other than starting from the left side of the screen?

Thanks.

1
Just add your own gesture recogniser.Petri

1 Answers

0
votes

Just add your own gesture recogniser and watch for gestures which velocity is greater in the x direction and going from left to right.

    override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {

        if (gestureRecognizer.isMemberOfClass(UIPanGestureRecognizer)){
            let point:CGPoint = (gestureRecognizer as UIPanGestureRecognizer).velocityInView(self)
            if (abs(point.x) > abs(point.y)){
                return true
            }
        }
}

Handle the gesture over here:

func handlePanGestureRecognizer(gesture: UIPanGestureRecognizer){
    let translation:CGPoint = gesture.translationInView(self)
    if(translation.x > 0){
       //its going from left to right...
       //...Do stuff over here to handle the gesture, for eg. push the view from the stack
    }


}