Class

UITouch

An object representing the location, size, movement, and force of a touch occuring on the screen.

Overview

You access touch objects through UIEvent objects passed into responder objects for event handling. A touch object includes accessors for:

  • The view or window in which the touch occurred

  • The location of the touch within the view or window

  • The approximate radius of the touch

  • The force of the touch (on devices that support 3D Touch or Apple Pencil)

A touch object also contains a timestamp indicating when the touch occurred, an integer representing the number of times the user tapped the screen, and the phase of the touch in the form of a constant that describes whether the touch began, moved, or ended, or whether the system canceled the touch.

To learn how to work with swipes, read Handling Swipe and Drag Gestures in Event Handling Guide for UIKit Apps.

A touch object persists throughout a multi-touch sequence. Never retain a touch object when handling an event. If you need to keep information about a touch from one touch phase to another, copy that information from the touch.

The gesture​Recognizers property of a touch contains the gesture recognizers currently handling the touch. Each gesture recognizer is an instance of a concrete subclass of UIGesture​Recognizer.

Symbols

Getting the Location of a Touch

func location(in:​ UIView?)

Returns the current location of the receiver in the coordinate system of the given view.

func previous​Location(in:​ UIView?)

Returns the previous location of the receiver in the coordinate system of the given view.

var view:​ UIView?

The view to which touches are being delivered, if any.

var window:​ UIWindow?

The window in which the touch initially occurred.

var major​Radius:​ CGFloat

The radius (in points) of the touch.

var major​Radius​Tolerance:​ CGFloat

The tolerance (in points) of the touch’s radius.

func precise​Location(in:​ UIView?)

Returns a precise location for the touch, when available.

func precise​Previous​Location(in:​ UIView?)

Returns a precise previous location for the touch, when available.

Getting Touch Attributes

var tap​Count:​ Int

The number of times the finger was tapped for this given touch.

var timestamp:​ Time​Interval

The time when the touch occurred or when it was last mutated.

var type:​ UITouch​Type

The type of the touch.

var phase:​ UITouch​Phase

The phase of the touch.

var force:​ CGFloat

The force of the touch, where a value of 1.0 represents the force of an average touch (predetermined by the system, not user-specific).

var maximum​Possible​Force:​ CGFloat

The maximum possible force for a touch.

var altitude​Angle:​ CGFloat

The altitude (in radians) of the stylus.

func azimuth​Angle(in:​ UIView?)

Returns the azimuth angle (in radians) of the stylus.

func azimuth​Unit​Vector(in:​ UIView?)

Returns a unit vector that points in the direction of the azimuth of the stylus.

Managing Estimated Touch Attributes

var estimated​Properties:​ UITouch​Properties

A set of touch properties whose values contain only estimates.

var estimated​Properties​Expecting​Updates:​ UITouch​Properties

The set of touch properties for which updated values are expected in the future.

var estimation​Update​Index:​ NSNumber?

An index number that lets you correlate an updated touch with the original touch.

Getting a Touch Object’s Gesture Recognizers

var gesture​Recognizers:​ [UIGesture​Recognizer]?

The gesture recognizers that are receiving the touch object.

Working with Touch Events in Sprite Kit

func location(in:​ SKNode)

Returns the current location of the receiver in the coordinate system of the given node.

func previous​Location(in:​ SKNode)

Returns the previous location of the receiver in the coordinate system of the given node.

Constants

UITouch​Type

The type of touch received.

UITouch​Properties

A bit mask of touch properties that may get updated.

UITouch​Phase

The phase of a finger touch.

Relationships

Inherits From