Introduction to Event handling event delivery:
After a touch event occurs, the system adds the event to an event queue managed by UIApplication, uiapplication the first event from the event queue and distributes the event for processing, typically Send an event to the application's main window first (Keywindow)
UIView does not accept three cases of touch events:
Do not receive user interaction
userInteractionEnabled = NO
Hide
hidden = YES
Transparent
alpha = 0.0 ~ 0.01
Tip: Uiimageview's userinteractionenabled default is no, so Uiimageview and its child controls cannot receive touch events by default.
Detailed procedure for event delivery:
The
main window will find the most appropriate view in the view hierarchy
to handle touch events , but this is just the first step in the entire event processing process. After the appropriate view control is found, the touches method of the view control is called to do the specific event handling
Touchesbegan ...
Touchesmoved ...
Touchedended ... The
default practice of these touches methods is to pass the event up the
responder chain , handing the event to the
previous responder for processing
Example:
Responder Chain
The complete process of event delivery
first pass the event object from top to bottom (passed by the parent control to the child control), and find the most appropriate control to handle the event. Call the touches of the most appropriate control .... method if a [super touches ...] is called, the event is passed up the responder chain, passed to the previous responder, and then called the previous responder's touches ... method
How to determine the previous responder
If the current view is a view of the controller, then the controller is the last responder if the current view is not the view of the controller, then the parent control is the previous responder
The event passing process of the responder chain
If view is a view of the controller, it is passed to the controller, if not, it is passed to its parent view in the top-most view of the view hierarchy, and if it cannot process the received event or message, it passes the event or message to the Window object for processing if the window object does not handle , it passes an event or message to the UIApplication object if UIApplication cannot process the event or message, discarding it
Note Why you use queues to manage events instead of stacks?
Queue FIFO First, can ensure that the first occurrence of the event first processing. Stack advanced after out.
iOS Development UI chapter-responder Chain