A responder chain
1.1hitTest:withEvent
This function returns the view on which the touch point is located when the touch event occurs. function execution principle is as follows
If the user clicked View E, the following describes the Hit-test view process
1, A is the root view of UIWindow, therefore, the Uiwindwo object will be the prime minister of a hit-test;
2, obviously the user clicks the scope is within the range of a, therefore,pointinside:withevent: Returns the Yes, then will continue to check A's child view;
3. At this time there will be two branches, B and C:
The clicked range is no longer within B, so the pointinside:withevent of the B branch : Return no, corresponding to the hittest:withevent: return nil;
Click on the range in C, that is, C pointinside:withevent: return yes;
4. There are two branches of D and E:
The clicked Range is no longer in D, so the pointinside:withevent of D : Return no, corresponding to the hittest:withevent: return nil;
The clicked Range is within E, that is, E's pointinside:withevent: Returns Yes, because E has no child view (which can also be understood as hit-test when the sub-view of E is returned nil), therefore, the hitTest of e : Withevent: will return E, and then back back, is the hittest:withevent of C : return e--->>a hittest:withevent: Return E.
At this point, the first responder of this click event is successfully found through the event distribution logic of the responder chain.
1.2 Responder Chain
If the view, or the first responder, returned by the initialization object (the initial objects)--hittest function does not handle the event, Uikit passes the event to the next responder on the responder chain. Each responder object can decide whether to handle the event or pass an event to the next responder on the responder chain through the Nextresponder function. The process continues until a single responder handles the event, or no responder handles the event.
When iOS detects an event and passes it to the initialization object, the responder chain begins. Initializing an object (typically a view) is the first object in the responder chain that has the opportunity to process the event.
Shows the two scenarios in which events are distributed on the responder chain:
The following is an explanation of the situation on the left, and its event delivery path is as follows
1. Initial view attempts to process an event or message, and if he cannot handle it, he will pass the event or message to his parent view (Superview)
2. Superview attempts to process, and if he cannot handle it, he then passes the event or message to his parent view (Superview)
3. This is done until the topmost view (topmost view) of the responder chain decides whether to process it, and if topmost view is not processed, the view controller passed to topmost view
4. The view controller attempts to process, and if he does not process, this is passed to window
5. If window does not process, it is passed to application, i.e. [UIApplication sharedapplication]
6. If application is not processed, the event will be discarded.
Reference: Https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/event_ Delivery_responder_chain/event_delivery_responder_chain.html#//apple_ref/doc/uid/tp40009541-ch4-sw1
Http://www.cnblogs.com/snake-hand/p/3178070.html
iOS Event handling