Game World!

Join A World Of Gamers

Enter your email address:

Delivered by FeedBurner

Followers

Popular Posts

Sunday, 27 June 2021

What is UI responder?

 Class

UIResponder

An abstract interface for responding to and handling events.

Declaration

@MainActor class UIResponder : NSObject

Overview

Responder objects—that is, instances of UIResponder—constitute the event-handling backbone of a UIKit app. Many key objects are also responders, including the UIApplication object, UIViewController objects, and all UIView objects (which includes UIWindow). As events occur, UIKit dispatches them to your app's responder objects for handling.

There are several kinds of events, including touch events, motion events, remote-control events, and press events. To handle a specific type of event, a responder must override the corresponding methods. For example, to handle touch events, a responder implements the touchesBegan(_:with:)touchesMoved(_:with:)touchesEnded(_:with:), and touchesCancelled(_:with:) methods. In the case of touches, the responder uses the event information provided by UIKit to track changes to those touches and to update the app's interface appropriately.

In addition to handling events, UIKit responders also manage the forwarding of unhandled events to other parts of your app. If a given responder does not handle an event, it forwards that event to the next event in the responder chain. UIKit manages the responder chain dynamically, using predefined rules to determine which object should be next to receive an event. For example, a view forwards events to its superview, and the root view of a hierarchy forwards events to its view controller.

Responders process UIEvent objects but can also accept custom input through an input view. The system's keyboard is the most obvious example of an input view. When the user taps a UITextField and UITextView object onscreen, the view becomes the first responder and displays its input view, which is the system keyboard. Similarly, you can create custom input views and display them when other responders become active. To associate a custom input view with a responder, assign that view to the inputView property of the responder.

For information about responders and the responder chain, see Event Handling Guide for UIKit Apps.

Topics

Managing the Responder Chain

Responding to Touch Events

Responding to Motion Events

Responding to Press Events

Generally, responders that handle press events should override all four of these methods.

Responding to Remote-Control Events

Managing Input Views

Getting the Undo Manager

Building and Validating Commands

Accessing the Available Key Commands

Managing the Text Input Mode

Supporting User Activities

Managing the Touch Bar

Constants

See Also

First Steps

Floating Button

Button