Get the App
SLTechnology News&Howtos  ›  Development  › 

Analyze the response chain and delivery chain of events in iOS

Shulou Source: shulou.com Published: 2022-06-02 17:57:06 09月17日 Update

This article focuses on "analyzing the response chain and delivery chain of events in iOS". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "analyzing the response chain and delivery chain of events in iOS".

There are two iOS event chains: the response chain of events and the delivery chain of Hit-Testing events.

Response chain: passed to the system by the view closest to the user. Initial view-> super view->... .. -> view controller-> window-> Application-> AppDelegate delivery chain: passed from the system to the nearest view to the user. UIKit-> active app's event queue-> window-> root view->. -> lowest view

In iOS, only objects that inherit UIResponder can receive and handle events. UIResponder is the base class of all response objects, and interfaces for handling these events are defined in the UIResponder class. The familiar UIApplication, UIViewController, UIWindow and all the UIKit classes that inherit from UIView inherit directly or indirectly from UIResponder, so their examples are responder objects that can form a responder chain. First of all, let's take a brief look at the transmission and response of events through a diagram.

1. Transfer chain

Two core methods of event delivery

-(nullable UIView *) hitTest: (CGPoint) point withEvent: (nullable UIEvent *) event; / / recursively calls-pointInside:withEvent:. Point is in the receiver's coordinate system- (BOOL) pointInside: (CGPoint) point withEvent: (nullable UIEvent *) event; / / default returns YES if point is in bounds

The first method returns a UIView, which is used to find out which view will respond to the event.

The second method is used to determine whether the location of a click is within the view range, and if so, return YES

Among them, UIView does not accept event handling.

1. Alpha

Tags: Events views methods objects processing responders coordinates controls analysis regions coordinate systems controllers processes users systems ranges controls reverse order content circles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL Microsoft Xiaomi NVidia