Problems with UISwipeGestureRecognizer, UITapGestureRecognizer and MPMoviePlayerController :-(
-
27-09-2019 - |
Question
This has me completely stumped!
I have a Tap Gesture Recognizer for show/hide menus...
I also have a Swipe Gesture Recognizer for swiping left and right between screens...
I then also have an MPMoviePlayerController for playing back video on the screen.
I am implementing gestureRecognizer:shouldReceiveTouch:
and excluding all UIControls and anything that has the prefix "MP".
Problem is, whenever I swipe left and right on the movie player controls, the shouldReceiveTouch
only notices the Tap Gesture Recognizer, NOT the swipe one. It also traces NO correctly, and yet STILL triggers the swipe method.
I've tried looking at gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer
but that's just REALLY confused me, because it also contains a UIPanGestureRecognizer... Where did THAT come from?
Please help, I am tired and have a big deadline... and can't work it out :(
Thank you all!
:-Joe
Solution 2
Okay, I must apologise... The reason it wasn't receiving shouldReceiveTouch
messages was because I wasn't setting its delegate!! What a numpty. I was setting the delegate for the tap gesture, but not the swipe one. Now it's all working fine.
Sorry! :-)
OTHER TIPS
I'd the same problem. Here's what I did to overcome the problem. In the [self doSomething...] methods I do some animation and if the animation finishes it sets the enabled state of the recognizer back to YES. Be aware of the fact, that you set the correct recognizer back to enabled! (here I have to (left/right), so the gestureRecognizers array has 2 entries.
- (void)handleSwipeGesture:(UISwipeGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateEnded && recognizer.enabled) { recognizer.enabled = NO; if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) { [self doSomethingInteresting]; } else { [self doSomethingElseInteresting]; } } }
[UIView transitionWithView:self.containerView duration:kAnimationDuration options:UIViewAnimationOptionTransitionCurlDown animations:^{ your animations } completion:^(BOOL finished) { if (self.containerView.gestureRecognizers.count) { ((UISwipeGestureRecognizer *)[self.containerView.gestureRecognizers objectAtIndex:0]).enabled = YES; } }];