iOS event delivery and response

First, when an incident response occurs, you must know who will respond to the incident. In IOS, the responder chain responds to events. All event response classes are subclasses of UIResponder. The responder chain is a hierarchical structure composed of different objects, each of which will receive response event messages in turn. Opportunity. When an event occurs, the event is first sent to the first responder. The first responder is often the view where the event occurs, that is, where the user touches the screen. Events are passed down the responder chain until they are accepted and handled. Generally speaking, the first responder is a view object or its subclass object. When it is touched, the event is handed over to it for processing. If it does not handle it, the event will be passed to its view controller object viewcontroller (if it exists ), then its superview object (if it exists), and so on, up to the top-level view. Next, we will follow the top view (top view) to the window (UIWindow object) and then to the program (UIApplication object). If the entire process does not respond to the event, the event is discarded. Normally, events stop being delivered as soon as an object handles the event in the responder chain.

When an event occurs, the event will be passed from the parent control to the child control, that is, from UIApplication -> UIWindow -> UIView -> initial view. The above is the transmission of the event, which is the process of finding the most suitable view.

Next is the response to the incident. First, see if the initial view can handle the event. If it cannot, the event will be passed to its superior view (superView of the initial view); if the superior view still cannot handle it, it will continue to be passed up; it will be passed to the view controller. First determine whether the root view of the view controller can handle this event; if not, then determine whether the view controller can handle this event. If it still cannot, continue to pass it upward; (for the second diagram, the view controller itself is still In another view controller, it will continue to be handed to the root view of the parent view controller. If the root view cannot handle it, it will be handed to the parent view controller.); all the way to the window, if the window still cannot handle the event, it will continue to be handed to the application. Processing, if the application still cannot handle this event, it will be discarded

In the event response, if a control implements the touches... method, the event will be accepted by the control. If [supertouches...]; is called, the event will be passed up the responder chain and passed to the previous A responder; then the touches... method of the previous responder will be called.

The difference between event delivery and response:

The event is transmitted from top to bottom (parent control to child control), and the response of the event is from bottom to top (upward along the responder chain: child control to parent control).

Original address: https://www.jianshu.com/p/bf9e67aeb929

Guess you like

Origin blog.csdn.net/qq_31709953/article/details/99357529