Daily iOS
UIKit

Responder chain and hit testing

When you tap the screen in a UIKit app, how does the system decide which view receives the touch (hit testing)?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Starting from UIWindow, hitTest(_:with:) recursively walks the subviews in reverse order, finds the deepest view whose point(inside:) returns true, and hands it the touch.

Share a question