Class
UIResponder
Availability
- iOS 2.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- UIKit
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, UIView
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 touches
, touches
, touches
, and touches
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 UIText
and UIText
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 input
property of the responder.
For information about responders and the responder chain, see Event Handling Guide for UIKit Apps.
Topics
Managing the Responder Chain
var next: UIResponder?
nil
if there is no next responder.var is First Responder: Bool
var can Become First Responder: Bool
func become First Responder() -> Bool
var can Resign First Responder: Bool
func resign First Responder() -> Bool
Responding to Touch Events
func touches Began(Set<UITouch>, with: UIEvent?)
func touches Moved(Set<UITouch>, with: UIEvent?)
func touches Ended(Set<UITouch>, with: UIEvent?)
func touches Cancelled(Set<UITouch>, with: UIEvent?)
func touches Estimated Properties Updated(Set<UITouch>)
Responding to Motion Events
func motion Began(UIEvent .Event Subtype, with: UIEvent?)
func motion Ended(UIEvent .Event Subtype, with: UIEvent?)
func motion Cancelled(UIEvent .Event Subtype, with: UIEvent?)
Responding to Press Events
func presses Began(Set<UIPress>, with: UIPresses Event?)
func presses Changed(Set<UIPress>, with: UIPresses Event?)
func presses Ended(Set<UIPress>, with: UIPresses Event?)
func presses Cancelled(Set<UIPress>, with: UIPresses Event?)
Responding to Remote-Control Events
func remote Control Received(with: UIEvent?)
Managing Input Views
var input View: UIView?
var input View Controller: UIInput View Controller?
var input Accessory View: UIView?
var input Accessory View Controller: UIInput View Controller?
func reload Input Views()
Getting the Undo Manager
var undo Manager: Undo Manager?
Building and Validating Commands
func build Menu(with: UIMenu Builder)
func validate(UICommand)
func can Perform Action(Selector, with Sender: Any?) -> Bool
func target(for Action: Selector, with Sender: Any?) -> Any?
Accessing the Available Key Commands
var key Commands: [UIKey Command]?
Managing the Text Input Mode
var text Input Mode: UIText Input Mode?
var text Input Context Identifier: String?
class func clear Text Input Context Identifier(String)
var input Assistant Item: UIText Input Assistant Item
Supporting User Activities
var user Activity: NSUser Activity?
func restore User Activity State(NSUser Activity)
func update User Activity State(NSUser Activity)
Managing Activity Items
Accessing the Editing Interaction
Managing the Touch Bar
func make Touch Bar() -> NSTouch Bar?
var touch Bar: NSTouch Bar?
Constants
class let keyboard Animation Curve User Info Key: String
class let keyboard Animation Duration User Info Key: String
class let keyboard Did Change Frame Notification: NSNotification .Name
class let keyboard Did Hide Notification: NSNotification .Name
class let keyboard Did Show Notification: NSNotification .Name
class let keyboard Frame Begin User Info Key: String
class let keyboard Frame End User Info Key: String
class let keyboard Is Local User Info Key: String
class let keyboard Will Change Frame Notification: NSNotification .Name
class let keyboard Will Hide Notification: NSNotification .Name
class let keyboard Will Show Notification: NSNotification .Name
Instance Methods
Relationships
Inherits From
See Also
First Steps
class UIEvent