UIResponder class defines an interface for objects that respond to and handle events. It is the superclass of
UIView and its subclasses (which include
UIWindow). Instances of these classes are sometimes referred to as responder objects or, simply, responders.
- iOS 2.0+
- tvOS 2.0+
There are two general kinds of events: touch events and motion events. The primary event-handling methods for touches are
touchesCancelled(_:with:). The parameters of these methods associate touches with their events—especially touches that are new or have changed—and thus allow responder objects to track and handle the touches as the delivered events progress through the phases of a multi-touch sequence. Any time a finger touches the screen, is dragged on the screen, or lifts from the screen, a
UIEvent object is generated. The event object contains
UITouch objects for all fingers on the screen or just lifted from it.
iOS 3.0 introduced system capabilities for generating motion events, specifically the motion of shaking the device. The event-handling methods for these kinds of events are
motionCancelled(_:with:). Additionally for iOS 3.0, the
canPerformAction(_:withSender:) method allows responders to validate commands in the user interface while the
undoManager property returns the nearest
UndoManager object in the responder chain.
In iOS 4.0,
UIResponder added the
remoteControlReceived(with:) method for handling remote-control events.