Event transmission and corresponding chain, event transmission chain

Source: Internet
Author: User

Event transmission and corresponding chain, event transmission chain

Aside from the title above, This article focuses on how the system finds the control that needs to respond to the touch event when you touch the screen of your mobile phone, and the control's response to the touch event

First, find the process to respond to the touch Event Control: the touch event is first detected by the message loop mechanism of the application, added to the message queue, to process the message, the application asked down the window, and the window asked rootcontroller again (this touch point is not in your view range). The rootcontroller asked his view again, view asked all its child controls for filtering,

The filtering rules are as follows:

1. Can I receive touch events? 2. Is the touch point on yourself? 3. all of the above satisfies the requirement of traversing the child control from the back to the back and repeating the previous two steps 4. if there is no child control that meets the conditions, it is best to handle the "Question" here. By default, it is through the control-(UIView *) hitTest :( CGPoint) point withEvent :( UIEvent *) the event method is used one by one from the outside to the inside; find the control that best suits to handle the touch event, by default, this control will handle touch events: (the following should be the content of the responder chain) according to the default responses of the control to events, there are about three (certainly more than): 1. button: by default, the system will process and respond to this event, and will not call [super touchesBegan: touches withEvent: event]; throw a response up, so that the response chain is broken; 2. uiview: If the uitouches method is not implemented, the touches method in the parent class (uiresponser) is called by default. By default, the system automatically submits the response to the next responder. 3. uiimagev Iew: by default, it does not interact with users. Therefore, this control is not selected as the best event handling control by default. Therefore, this type should not be counted; if the control implements the touches method to handle touch events and calls [super touchesBegan: touches withEvent: event] After the response is complete, the next responder can continue to respond, in this way, a layer from the inside to the outside forms the responder chain. It should be noted that not all responders must be views and other controls, or may be viewController and other controllers (UIviewController also inherits UIresponser ); the principle for finding the next responder is: 1> if the current view is the Controller's view, the controller is the previous Responder (The Controller also inherits UIResponser, and all controllers also have touches ...... Method) 2> if the current view is not the Controller view, the parent control is the event Transfer Process of the previous responder chain: 1. if the view Controller exists, it is passed to the Controller; if the Controller does not exist, it is passed to its parent view 2. in the top-level view of the view hierarchy, if the received event or message cannot be processed, the event or message is transmitted to the window object for processing. 3. if the window object is not processed, it will pass the event or message to the UIApplication object 4. if UIApplication cannot process this event or message, discard it.

Related Article

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.