UIAcceleration Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 2.0 and later.
Deprecated in iOS 5.0.
Declared in
UIAccelerometer.h
Related sample code

Overview

An instance of the UIAcceleration class, called an acceleration event, represents immediate, three-dimensional acceleration data. To receive accelerometer events, register an application object as a delegate of the shared UIAccelerometer object, as described in UIAccelerometer Class Reference.

Each acceleration event includes simultaneous acceleration readings along the three axes of the device, as shown in Figure 1.

Figure 1  Orientation of the device axes
Orientation of the device axes

The device accelerometer reports values for each axis in units of g-force, where a value of 1.0 represents acceleration of about +1 g along a given axis. When a device is laying still with its back on a horizontal surface, each acceleration event has approximately the following values:

x: 0
y: 0
z: -1

Individual acceleration values are of type UIAccelerationValue, equivalent to a double. Values can range over the accelerations found in normal use of a device.

If you want to detect specific types of motion as gestures—specifically, shaking motions—use the UIEvent class and its UIEventTypeMotion event type. For details, see “Motion Events” in Event Handling Guide for iOS.

Tasks

Accessing the Acceleration Values

Properties

timestamp

The relative time at which the acceleration event occurred. (read-only)

@property(nonatomic, readonly) NSTimeInterval timestamp
Discussion

This value indicates the time relative to the device CPU time base register. Compare acceleration event timestamps to determine the elapsed time between them. Do not use a timestamp to determine the exact time at which an event occurred.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIAccelerometer.h

x

The acceleration value for the x axis of the device. (read-only)

@property(nonatomic, readonly) UIAccelerationValue x
Discussion

With the device held in portrait orientation and the screen facing you, the x axis runs from left (negative values) to right (positive values) across the face of the device.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIAccelerometer.h

y

The acceleration value for the y axis of the device. (read-only)

@property(nonatomic, readonly) UIAccelerationValue y
Discussion

With the device held in portrait orientation and the screen facing you, the y axis runs from bottom (negative values) to top (positive values) across the face of the device.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIAccelerometer.h

z

The acceleration value for the z axis of the device. (read-only)

@property(nonatomic, readonly) UIAccelerationValue z
Discussion

With the device held in portrait orientation and the screen facing you, the z axis runs from back (negative values) to front (positive values) through the device.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UIAccelerometer.h

Constants

UIAccelerationValue

The amount of acceleration in a single linear direction.

typedef double UIAccelerationValue;
Discussion

This type is used to store acceleration values, which are specified as g-force values, where the value 1.0 corresponds to the normal acceleration caused by gravity at the Earth’s surface.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIAccelerometer.h