This article link address : http://www.linuxidc.com/Linux/2015-08/121270.htm
First, let's look at the process of generating and passing events in iOS:
1. After a touch event occurs, the system adds the event to a queue event managed by uiapplication
2.UIApplication takes the first event out of the event queue and distributes the event for processing, typically sending an event to the application's main window (Keywindow)
3. The main window will find the most appropriate view in the view hierarchy to handle touch events
4. Once the appropriate view control is found, the touches method of the view control is invoked to handle the event specifically: Touchesbegin ... touchesmoved...touchesended, etc.
5. The default practice of these touches methods is to pass the event up the responder chain and call the event a corresponding person for processing
Let's give an example to illustrate the specific delivery process,
A generic event is passed from the parent control to the child control.
For example: Click on the Green view, the transfer process is as follows:uiapplication->window-> white view-> Green View
Click the blue view and pass the process as follows:uiapplication->window-> white view-> Orange view-> Blue View
A child control cannot receive a touch event if the parent control accepts no touch events
UIView cannot receive three cases of touch events:
1. User interaction is not accepted: userinteractionenabled = no;
2. Hide: hidden = YES;
3. Transparent: Alpha = 0.0~0.01
How do I find the most appropriate control to handle an event? There are the following guidelines
1. Whether you can accept touch events
2. Whether the touch point is on its own
3. Iterate through the child controls, repeating the two steps above
4. If there are no child controls that meet the criteria, then you are best suited to handle
For example:
Describe the order in which the controls are added: White 1-> green 2-> orange 2-> Blue 3-> red 3-> Yellow 4
Here you click on the Orange area, and the event pass judgment process is as follows:
1.UIApplication removing events from the event queue distribution to UIWindow
2.UIWindow determine if you can accept touch events, you can
3.UIWindow determine if touch points are on their own, yes.
4.UIWindow to facilitate your own child control from the back, remove the white 1
5. White 1 Meet the top two conditions, traverse the child control Orange 2
6. Orange 2 Meet the top two conditions, traverse the child control, first remove the Red 3
7. Red 3 does not meet the condition 2, remove the Blue 3
8. Blue 3 also does not meet the condition 2, the last most suitable control is the Orange 2
After finding the right controls to respond, here's a look at the responder chain: The responder chain is actually a lot of responder objects (objects that inherit from Uiresponder) are grouped together as chains called responder chains
The general default is that the control passes the event up the responder chain, handing the event over to the previous responder for processing. So how do you judge the last responder of the current responder? The following two rules are available:
1. Determine whether the controller is currently a view, if the controller's view, the previous responder is the controller
2. If not the controller's view, the previous responder is the parent control
The response process is as follows:
If the controller does not respond to the response touches method, it is given to UIWindow. If the UIWindow also does not respond, to uiapplication, if all do not respond to the event is void.
In conclusion, a complete touch event delivery response process is:
Uiapplication-->uiwindow--> recursively finds the most appropriate control--the control calls the touches method--to determine if the touches method is implemented-- No implementation by default passes an event to the previous responder--finds the previous responder--Cannot find the method obsolete
PS: Using the responder chain we can have multiple responders respond to the event at the same time by calling touches's Super method.
Event Delivery and responder chain