13

I've got a little problem with the UIPanGestureRecognizer. The Recognizer does not report the UIGestureRecognizerStateEnded state if the user panned to the top left (means negative x and y directions)

The state changes to UIGestureRecognizerStateEnded if any direction is positive when the user lifts his finger, but it just ceases to report actions if both directions are negative or zero.

This is bad because i hide some overlay views as long as the user drags something around and those views do not return in failure case.

Of course I could setup a NSTimer to display the overlay after some time automatically again but i can see no obvious error in my code and I want it clean.

Is there something i missed? Is it an Apple Bug?

Initialization is like this:

pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panRecognized:)];
[self addGestureRecognizer:pan];
[pan release];

The handling function looks like this:

- (void)panRecognized:(UIPanGestureRecognizer *)gestureRecognizer {
    switch ([gestureRecognizer state]) {
        case UIGestureRecognizerStateBegan:
            // fade some overlaying views out
            break;
        case UIGestureRecognizerStateEnded:
        case UIGestureRecognizerStateCancelled:
        case UIGestureRecognizerStateFailed:
            // fade in the overlays
            break;
        default:
            break;
    }

    // handle panning
}
Sanjay Chaudhry
  • 3,181
  • 1
  • 22
  • 31
Dunkelstern
  • 1,624
  • 12
  • 18
  • 3
    This has happened to me in the past when I accidentally removed/moved the gesture recognizer to a different view. It will simply go silent as soon as you do. This is not the case in your case? – Kalle Jan 02 '13 at 08:03
  • Not sure exactly what's going on, but try logging state change by accounting for all possible UIGestureRecognizerStates to see what's happening during the interaction – Evan Davis May 08 '14 at 19:54
  • Happened to me too. Moving `uiview.addGestureRecognizer` from my VC's `viewDidLayoutSubviews` to `viewWillAppear` solved that, still looking for a justification. – Jokester Jun 02 '15 at 01:08

1 Answers1

0

The line

[self addGestureRecognizer:pan];

looks wrong to me.

It seems like you are creating the gesture recognizer from inside a UIView and not a UIViewController. So if the view is dealloc both it and the gesture recognizer will disappear.

Better to create the gesture recognizer from the UIViewController. Also the UIViewController needs to keep a strong point to the recognizer.

Hemang
  • 26,840
  • 19
  • 119
  • 186
Jon Rose
  • 8,373
  • 1
  • 30
  • 36