0

I want to implement back navigation, using longpress and swipe to the left, without lifting the finger, but the swipe gesture isn't recognised, if I don't lift the finger after the longpress.

I also implemented the following delegate method, but the desired result isn't appearing. Any thoughts?

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (gestureRecognizer == _longPress && otherGestureRecognizer == _swipe) {
    return YES;
}
if (gestureRecognizer == _swipe && otherGestureRecognizer == _longPress) {
    return YES;
}
return NO;

edit: - the longpress gesture fires method, which changes the background color of the current UIViewController (made it, just to see, if it fires). -the swipe gesture fires method, -popViewController:animated

P.Todorov
  • 43
  • 10

1 Answers1

0

Don't use 2 different gesture recognisers because this is 1 gesture. You should create a custom gesture subclass to encode your logic so it's a single logical gesture for you to add and for the user to execute.

Inside your gesture i'd have a small state machine so you know when you start, when the long press time is up, if they have actually swiped enough. From each state you're only looking for one thing to happen, if anything else happens then you know it's a failure and the gesture can fail out.

Wain
  • 118,658
  • 15
  • 128
  • 151