UI Responder Chain

Source: Internet
Author: User

Responder Chain Concept:

Each application has a responder chain, our view structure is an n-fork tree (a view can have multiple sub-views, a child view has only one parent view at a time), and every object that inherits Uiresponder can play a node in this N-fork tree. When the leaf node becomes the highest responder, starting from this leaf node to its parent node begins to chase a chain, then for this one leaf node, this chain is the current responder chain. The responder chain distributes the uievent captured by the system to the Uitouch from the leaf node, where you can choose to stop distribution, or you can choose to continue distributing downward.

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

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.

UI Responder Chain

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.