The generation and delivery of events:
- After a touch event occurs, the system adds the event to an event queue managed by the uiapplication;
- UIApplication takes the first event from the event queue and distributes the event for processing, typically sending an event to the application's main window (keywindow);
- The main window will find the most appropriate view in the view hierarchy to handle touch events, which is the first step in the entire event processing process;
- Once the appropriate view control is found, the touches method of the view control is invoked to handle the event in detail;
- Touchesbegan ...
- Touchesmoved ...
- touchedended ...
How do I find the most appropriate control to handle an event?
①. Determine if you can receive touch events?
control does not receive three cases of touch events
1> does not receive user interaction Userinteractionenabled=no
2> Hide hidden = YES
3> transparent alpha = 0.0 ~ 0.01
②. Determine if the touch point is on your own?
1, to judge the touch point is not on their own,view has a method "-(BOOL) Pointinside:withevent:"
2, return No, the representative is not on their side, that no longer traverse the child control
3, returns YES, represents the point on its own upward, that continues to traverse the child control
③. Iterate through the child controls backwards, repeating the previous two steps
④. If there are no child controls that meet the criteria, then the control that is most appropriate for your work
⑤. Call the touchesbegin/touchesmoved/touchesended method When you find the most appropriate control
Example of event delivery:
Touch Event Delivery is passed from parent control to child controlClick on the Green View:
UIApplication, UIWindow, white-green
Click on the Blue View:
UIApplication, UIWindow, white-orange blue
Click on the Yellow view:
UIApplication, UIWindow, White, orange and blue
Note: If the parent control cannot receive touch events, the child controls will not be able to receive touch events
UI advanced--touch event generation and delivery