响应链(一)

引用:https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/using_responders_and_the_responder_chain_to_handle_events

Using Responders and the Responder Chain to Handle Events

利用响应者和响应者链来处理事件;

Learn how to handle events that propagate through your app.

学会如何通过你的APP来处理事件;

Apps receive and handle events using responder objects. A responder object is any instance of the UIResponder class, and common subclasses include UIView, UIViewController, and UIApplication. Responders receive the raw event data and must either handle the event or forward it to another responder object. When your app receives an event, UIKit automatically directs that event to the most appropriate responder object, known as the first responder.

Unhandled events are passed from responder to responder in the active responder chain, which is the dynamic configuration of your app’s responder objects. Figure 1 shows the responders in an app whose interface contains a label, a text field, a button, and two background views. The diagram also shows how events move from one responder to the next, following the responder chain.

APP利用响应者对象来接收和处理事件。响应者对象是UIResponder的子类,公共子类包括 UIView, UIViewController, and UIApplication.响应者接收原始事件数据,必须要么处理事件,要么向下一个响应者传递。当APP接收到事件的时候,UIKit会自动传递事件到最合适的响应者,作为第一响应者。

未处理的时间会被从一个响应者到另一个响应者下表列出来了一个响应链:


响应者链

If the text field does not handle an event, UIKit sends the event to the text field’s parent UIViewobject, followed by the root view of the window. From the root view, the responder chain diverts to the owning view controller before directing the event to the window. If the window cannot handle the event, UIKit delivers the event to the UIApplication object, and possibly to the app delegate if that object is an instance of UIResponder and not already part of the responder chain.

如果UItextfield无法处理事件,UIKit会发送事件到他的父视图,接着即使往下传递。。。。。

你可能感兴趣的:(响应链(一))