Class

UIEvent

An object that describes a single user interaction with your app.

Overview

Apps can receive many different types of events, including touch events, motion events, remote-control events, and press events. Touch events are the most common and are delivered to the view in which the touch originally occurred. Motion events are UIKit triggered and are separate from the motion events reported by the Core Motion framework. Remote-control events allow a responder object to receive commands from an external accessory or headset so that it can manage manage audio and video—for example, playing a video or skipping to the next audio track. Press events represent interactions with a game controller, AppleTV remote, or other device that has physical buttons. You can determine the type of an event using the type and subtype properties.

A touch event object contains the touches (that is, the fingers on the screen) that have some relation to the event. A touch event object may contain one or more touches, and each touch is represented by a UITouch object. When a touch event occurs, the system routes it to the appropriate responder and calls the appropriate method, such as touchesBegan(_:with:). The responder then uses the touches to determine an appropriate course of action.

During a multitouch sequence, UIKit reuses the same UIEvent object when delivering updated touch data to your app. You should never retain an event object or any object returned from an event object. If you need to retain data outside of the responder method you use to process that data, copy that data from the UITouch or UIEvent object to your local data structures.

For more information on how to handle events in your UIKit app, see Event Handling Guide for UIKit Apps.

Symbols

Getting the Touches for an Event

var allTouches: Set<UITouch>?

Returns all touches associated with the event.

func touches(for: UIView)

Returns the touch objects from the event that belong to the specified given view.

func touches(for: UIWindow)

Returns the touch objects from the event that belong to the specified window.

func coalescedTouches(for: UITouch)

Returns all of the touches associated with the specified main touch.

func predictedTouches(for: UITouch)

Returns an array of touches that are predicted to occur for the specified touch.

Getting Event Attributes

var timestamp: TimeInterval

The time when the event occurred.

Getting the Event Type

var type: UIEventType

Returns the type of the event.

var subtype: UIEventSubtype

Returns the subtype of the event.

Getting the Touches for a Gesture Recognizer

func touches(for: UIGestureRecognizer)

Returns the touch objects that are being delivered to the specified gesture recognizer.

Constants

UIEventType

Specifies the general type of an event

UIEventSubtype

Specifies the subtype of the event in relation to its general type.

Relationships

Inherits From

Conforms To