TouchEvent Class Reference
| Inherits from | UIEvent : Event |
| Companion guide | |
| Availability | Available in iOS 2.0 and later. |
Overview
The TouchEvent class encapsulates information about a touch event.
The system continually sends TouchEvent objects to an application as fingers touch and move across a surface. A touch event provides a snapshot of all touches during a multi-touch sequence, most importantly the touches that are new or have changed for a particular target. A multi-touch sequence begins when a finger first touches the surface. Other fingers may subsequently touch the surface, and all fingers may move across the surface. The sequence ends when the last of these fingers is lifted from the surface. An application receives touch event objects during each phase of any touch.
The different types of TouchEvent objects that can occur are:
touchstartSent when a finger for a given event touches the surface.
touchmoveSent when a given event moves on the surface.
touchendSent when a given event lifts from the surface.
touchcancelSent when the system cancels tracking for the touch.
TouchEvent objects are combined together to form high-level GestureEvent objects that are also sent during a multi-touch sequence. See GestureEvent for details on GestureEvent objects and an example of the events sent for a two finger multi-touch gesture.
Properties
altKey
A Boolean value indicating whether the alt key is pressed.
readonly attribute boolean altKey
Discussion
If true, the alt key is pressed; otherwise, it is not. If there is no keyboard, this value is false.
Availability
- Available in iOS 2.0 and later.
changedTouches
A collection of Touch objects representing all touches that changed in this event.
readonly attribute TouchList changedTouches
Discussion
You manipulate this collection using TouchList methods.
Availability
- Available in iOS 2.0 and later.
ctrlKey
A Boolean value indicating whether the control key is pressed.
readonly attribute boolean ctrlKey
Discussion
If true, the control key is pressed; otherwise, it is not. If there is no keyboard, this value is false.
Availability
- Available in iOS 2.0 and later.
metaKey
A Boolean value indicating whether the meta key is pressed.
readonly attribute boolean metaKey
Discussion
If true, the meta key is pressed; otherwise, it is not. If there is no keyboard, this value is false.
Availability
- Available in iOS 2.0 and later.
rotation
The delta rotation since the start of an event in degrees where clockwise is positive and counter-clockwise is negative.
readonly attribute float rotation
Discussion
The initial value is 0.0.
Availability
- Available in iOS 2.0 and later.
scale
The distance between two fingers since the start of an event as a multiplier of the initial distance.
readonly attribute float scale
Discussion
The initial value is 1.0. If less than 1.0 the gesture is pinch close to zoom out. If greater than 1.0 the gesture is pinch open to zoom in.
Availability
- Available in iOS 2.0 and later.
shiftKey
A Boolean value indicating whether the shift key is pressed.
readonly attribute boolean shiftKey
Discussion
If true, the shift key is pressed; otherwise, it is not. If there is no keyboard, this value is false.
Availability
- Available in iOS 2.0 and later.
targetTouches
A collection of Touch objects representing all touches associated with this target.
readonly attribute TouchList targetTouches
Availability
- Available in iOS 2.0 and later.
touches
A collection of Touch objects representing all touches associated with this event.
readonly attribute TouchList touches
Availability
- Available in iOS 2.0 and later.
Methods
initTouchEvent
Initializes a newly created TouchEvent object.
Parameters
- type
The type of event that occurred.
- canBubble
Indicates whether an event can bubble. If
true, the event can bubble; otherwise, it cannot.- cancelable
Indicates whether an event can have its default action prevented. If
true, the default action can be prevented; otherwise, it cannot.- view
The view (DOM window) in which the event occurred.
- detail
Specifies some detail information about the event depending on the type of event.
- screenX
The x-coordinate of the event’s location in screen coordinates.
- screenY
The y-coordinate of the event’s location in screen coordinates.
- clientX
The x-coordinate of the event’s location relative to the window’s viewport.
- clientY
The y-coordinate of the event’s location relative to the window’s viewport.
- ctrlKey
If
true, the control key is pressed; otherwise, it is not.- altKey
If
true, the alt key is pressed; otherwise, it is not.- shiftKey
If
true, the shift key is pressed; otherwise, it is not.- metaKey
If
true, the meta key is pressed; otherwise, it is not.- touches
A collection of
Touchobjects representing all touches associated with this event.- targetTouches
A collection of
Touchobjects representing all touches associated with this target.- changedTouches
A collection of
Touchobjects representing all touches that changed in this event.- scale
The distance between two fingers since the start of an event as a multiplier of the initial distance. The initial value is
1.0. If less than1.0, the gesture is pinch close (to zoom out). If greater than1.0, the gesture is pinch open (to zoom in).- rotation
The delta rotation since the start of an event, in degrees, where clockwise is positive and counter-clockwise is negative. The initial value is
0.0.
Discussion
Use this method to programmatically create a TouchEvent object.
Availability
- Available in iOS 2.0 and later.
© 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-12-16)