Event Delivery: The Responder Chain (Event passing, response Chain), deliveryresponder

Source: Internet
Author: User

Event Delivery: The Responder Chain (Event passing, response Chain), deliveryresponder

When designing an app, we may want to respond dynamically to events. For example, to touch a screen with many different objects, you need to decide which object to send a response event and how the object receives the event.

When a user generates an event (such as a click), UIKit generates an object that contains the information of the object to be processed. Then, place the event object in the active app's (an application object that initializes user Event Routing and globally manages a running application) event queue. For a touch event, this object is a set of touch, packaged in a UIEvent object. For a motion event, the event object varies depending on the type of the motion event you are interested in using the framework.

An event object is passed along a specific path until an object can process it. First, the single-instance UIApplication object retrieves an event from the top of the queue and distributes it. Generally, the UIApplication object sends the event to the key window object of the application, and the key window object is passed to an initial object for processing. The initial object depends on the event type.

  • Touch events. For a touch event, the window object first tries to send the event to the view (hit-test view) where the event occurs ). The process of finding the hit-test view is called hit-testing (we will talk about it later ).
  • Motioin and remote control enents. For such events, window prawn ing sends shaking-motion or remote control events to the first responder.

The ultimate goal of event paths is to find an object to respond to an event. Therefore, UIKit first sends this event to the object most suitable for processing this time. For touch events, this object is hit-test view; for other events, this object is the first responder. The following section describes more details about how to determine the hit-test view and the first responder.

Hit-Testing Returns the View Where a Touch Occurred (hit-test Returns the view Where the Touch occurs ). In some cases, the translation is quite awkward. In order to avoid misleading (is someone really reading it ?), Paste the original text.

IOS use hit-testing fo find the view that is under a touch. hit-testing involves checking whether a touch is within the bounds fo any relevant (more emphasis on direct relevance) view objects. if it is, it recursively checks all of that view's subviews. the lowest view in the view hierarchy that contains the touch point becomes the hit-test view. after iOS determines the hit-test view, it passes the touch event to that view for handling.

For example, if you touch View E, iOS checks subviews in the following order to find the hit-test view:

HitTest: withEvent: return the hit-test view of a CGPoint and UIEvent. HitTest: withEvent: The method starts to run. Call pointInside: withEvent: method through view itself. If pointInside: withEvent: is passed in to the view bounds, pointInside: withEvent: YES is returned. Next, call hitTest: withEvent: on each subview of this view :.

The point passed in hitTest: withEvent: is not detailed in view bounds.

Note: A Touch event is associated with its hit-test view throughout its lifecycle, even if it is removed later.

Hit-test view is given the first chance to handle touch events. If the hit-test view cannot process this event, the event will go down along the responder chain of this view until an object that can process the event is found.

The Responder Chain Is Made Up of Responder Objects (The Responder Chain consists of The Responder -. -)

Many types of events are passed in response to chain events. The responder chain is a series of connected responder objects. Start with the first responder and end the application object. If the first responder cannot handle an event, it will forward it to the next responder in the responder chain.

AResponder objectIs an object that can respond to and handle events. the UIResponder class is the base class for all responder objects, and it defines the programmatic interface not only for event handling but also for common responder behavior. instances ofUIApplication,UIViewController, AndUIViewClasses are responders, which means that all views and most key controller objects are responders. Note that Core Animation layers are not responders.

The first responder is specified to accept the event first. Generally, the first responder is a view object. An object can become the first responder by doing the following two things:

Objects dependent on the responder chain are not only event objects. The responder chain can be used in the following places:

UIKit automatically sets the text field or text view clicked by the user to become the first responder. Apps must explicitly set all other first responders, using the becomeFirstResponder method.

 

More details: https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/event_delivery_responder_chain/event_delivery_responder_chain.html

Http://www.cnblogs.com/xjshi/p/4356018.html

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.