This article will explain the journey that an event takes from a touch on screen to UIView, TL;DR

HitTest

The touch is first received in the UIWindow then its hit tested using hitTest:withEvent which is sent to the all the subViews of the UIWindow

When hitTest:withEvent is received it calls pointInside:withEvent on self, if the result is YES, the view will call hitTest:withEvent on all its subviews starting by the last one added.

The operation of hitTest:withEvent will drill down till it reaches a leaf view, this view will be the hit tested view

A hit-tested view is the view that will receive the touches methods as the first responder, if this view do not implement these the touches method, the system will send the touches method to the next responder.

The next responder for the View its its superView, this will keep bubbling up, till it reaches a superView that is the View of a UIViewController, in that case the system will send the touches events to the Controller, Then to the Window and Then to the AppDelegate

Gesture recognizers

Gesture reconizers are classes that abstract the task of recognizing a gesture from a set of touches, decoupling gesture recognition from view presentation.

The gesture recognizer recognizes a gesture by investigating the gesture received from the hit-tested view. The system delivers the touches events to the gesture recognizer before the view its attached to, it gives the gesture a chance to recognize the gesture, then i delivers them to the view.

If a gesture recognizer succeed it will cancel the touches received by the hit-tested view.

Gesture recognizers do not participate in the responder chain, that allows multiple recognizers to receive the same touch.

Summary:
  • iOS determines which view received the touches by calling hitTest recursively on the View hierarchy
  • Hit testing is a drill down operation from the Window to the leaf view
  • Touches are first delivered to the gesture recognizers attached to the hit-tested view
  • Multiple gesture recognizers from different parts of the view hierarchy can receive the same touches.
  • After that the touches events are delivered to the hit-tested view.
  • If the hit-tested does not implement touch events, they are delivered to the Next Responder in the responder chain.