0
votes

I'm using a UIScreenEdgePanGestureRecognizer to change views and in one of the views I can use a UILongPressGestureRecognizer (with minimum duration of 0) to move a row in the table. The problem is, this press gesture is at the edge of the screen so I have to configure the delegates for them to work properly.

The delegate of the press gesture has been set:

override func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOfGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return otherGestureRecognizer is UIScreenEdgePanGestureRecognizer
}

This works fine in the simulator (since a housepainter is much more accurate) but on the device itself it's less reliable. I can change views without problems but moving the rows can still be a bit tricky.

So I changed it to:

override func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return gestureRecognizer is UILongPressGestureRecognizer && otherGestureRecognizer is UIScreenEdgePanGestureRecognizer
}

Now both are working fine but obviously both of the gestures are working at the same time which I don't want to. I tried setting a condition to fail the press gesture if the velocity of the x axis of the pan gesture is bigger than 0, but by then the press gesture has already started.

1

1 Answers

0
votes

One thing you can do is add a tag to each gesture recognizer and do something like:

func doSomething(sender: UIGestureRecognizer) {
    if sender.tag == 1 {
        // do this
    } else {
        // do that
    }
}