How to handle events by a view and then pass them to the view directly below?

I am trying to implement my own version of UIMenuController.

One of the things I am struggling to imitate is what happens when a there is a touch event outside the menu. In this case the menu will be dismissed, but the event will also be passed to the correct view .

So I need somehow to handle or capture the event in the menu or some transparent view covering the whole screen but also let it pass to the view below it.

One idea is to override hitTest:withEvent: of the menu view, dismiss the menu when it is called (if point is outside the menu) and then return nil as if it was transparent to events. The issue is that hitTest:withEvent: must be pure function without side effect.

On other hand, when touchesBegan:withEvent: is called, it is possible dismiss the menu and to pass the event to the nextResponder, but the view directly below the menu is not necessarily the superview of the menu view, so it is not part of the responder chain.

How to handle events by a view and then pass them to the view directly below?
 
 
Q