Search code examples
iosobjective-cuiviewuigesturerecognizer

iOS: pass gesture to views underneath


I have a simple setup: there are 2 sibling UIViews A and B, B fully covers A (but it is transparent, so A is visible):

┌──────────────────┐
│   View A         │
│                  │
│   ┌──────────────┴───┐
│   │   View B         │
│   │                  │
│   │                  │
│   │                  │
│   │                  │
│   │                  │
└───┤                  │
    │                  │
    │                  │
    └──────────────────┘

I need 2 different UIGestureRecognizers: A should have a tap recognizer and B should have a pan recognizer. Whenever I tap on B it should pass the touch events to view A behind so that it can recognize a tap (I will use some logic to understand if pan was accepted or not, like distance, start area, etc). Is this possible to do in iOS?

My experience so far is that once B accepts a touch it will never forward it to A which is behind. And the decision to accept or not should be done immediately in overriden pointInside or hitTest functions. However, in my case the decision is based on some logic and depends on the context and history of user interaction.


Solution

  • If B covers A, it's going to prevent A from receiving gestures. But why do you have this transparent B over A? Get rid of B and put both gestures on A. And then you can define the tap gesture to require the pan gesture to fail.