Some gestures aren't working the 1st time

I have an iOS app that's giving me a pain. One view hierarchy has a scroll view, page view, and other views. The storyboard has 5 gesture recognizers scattered among a couple of the view controllers. The code has a few shouldBeRequiredToFailByGestureRecognizer and shouldRequireFailureOfGestureRecognizer delegate methods. The problem I'm seeing is that right after I segue to this view hierarchy and attempt to use one particular gesture (long press with 1 tap), the delegate doesn't even get the gestureRecognizerShouldBegin message, but eventually seemingly times out and other gestures will fire, such as my single tap gesture or the page view's next page gesture. But after doing ANY gesture, this gesture behaves like it should from then on.


I've tried logging all the pairs of gesture recognizers sent to all of the delegate methods. The strange thing is that the logged pairs of gesture recognizers is different on that first attempt to use the gesture in question than it is on every other time, with more pairs being checked the first time.


I was hoping the Simulator or Xcode had some sort of gesture debugging, like a way to spit out info about which gesture recognizers were attempted, failed, skipped, etc. But nope. So, what things can I try? I'm at a loss.

You should explain the view hierarchy more in detail and which gestures are associated to what. And which don't work.

Need to be cautious with scroll view which may intercept gesture.


Maybe also the view which has the gesture has not the focus yet. Once you tap on it, it gets focus, hence react to gestures.


You could set focus in viewDidAppear, with call to becomeFirstResponder()


Could you post the code as well, to see if that's something else.

MasterViewController

single tap gesture recognizer

UIView 1

embedding view controller (embeds UIPageViewController subclass on triggered segue viewDidLoad)

UIPageViewController subclass

single tap gesture recognizer

AnotherViewController

double tap gesture recognizer

long press gesture recognizer

tap & hold gesture recognizer (the gesture that doesn't work the first time)

UIView 2

UIScrollView

UIImageView


I added [self.view becomeFirstResponder] to AnotherViewController's viewDidLoad. That didn't do anything because UIView 2 returns NO for canBecomeFirstResponder.


Tried adding the problem gesture recognizer to UIView 2 instead of the scroll view. It too refuses first responder.


I didn't think gesture recognizers had anything to do with first responders. It mentions something about that somewhere in the docs.


I can't show code - there's far too much, plus the large storyboard.

Is tap and hold a custom gesture ?


When it does not work, what is the other gesture that is fired ? LongPress ?


If so, could you show how it is defined ? And initialized in code.

No, tap & hold is a standard gesture, UILongPressGestureRecognizer with 1 tap.


It depends on where I do the gesture. If I do it along the left or right edges, it triggers the single tap gesture for changing prev/next page that the UIPageViewController has by default, or if it's already on the last page, it triggers my single tap gesture which asks the user what they want to do. If I do the gesture anywhere else within my view hierarchy, it triggers my long press gesture.


All gesture recognizers are created in the .storyboard, not by code, and all use the standard settings:

Cancels touches in view = YES

Delays touches began = NO

Delays touches ended = YES

Some gestures aren't working the 1st time
 
 
Q