iOS Interview Prep 4 — Event Handling & Responder Chain
Published in
4 min readMay 2, 2023
Event handling and the responder chain are very important concepts in iOS development, they are the fundamental and primary mechanism used for managing user interactions with the UI. Understanding how it works, you can not only ensure your app’s UI is responsive, but also be able to customize the way events are handled in your app.
Interview Questions
- Explain how hit testing works?
- What is the UIResponder object? Why is it useful, what does it enable you to do?
- How are events propagated and dispatched through the system via UIResponder?
- Explain the iOS Responder Chain?
- Why UIButton is not responsive?
Hit Testing
Hit testing is a process used in iOS to determine which view is currently under user’s finger or cursor. iOS uses hit-testing to determin which view is the frontmost view under the user’s finger.
The hit-testing process involves several steps:
- OS generates events containing touch location
- It then starts at the root view of the UI and checks if the touch point is within the bounds of a view. It is using an approach similar to DFS search algorithm.
- It iterates all the subviews, checking if the touch point is within the bounds of any subview.
- If a subview is a potential hit-test view, the…