Chapter 37

Introduction to Core Motion

Motion sensing has proven to be an effective input technique in applications, particularly games. All iOS devices have had the capability to detect motion, and most achieve this using an accelerometer. Starting with iPhone 4 and iPad 2, Apple has included a gyroscope in addition to the standard accelerometer found in its predecessors.

As far as developing motion-aware applications, accelerometer events have traditionally been available to applications through the UIAccelerometer class. Starting with iOS4, Apple has provided a new framework called Core Motion that exposes the functionality of both the accelerometer and the gyroscope (when available).

note.eps
You can’t test accelerometer and gyroscope functionality in the iOS Simulator. You will need to test any apps that require Core Motion on a real device.

Accelerometers and Gyroscopes

An accelerometer is a device that measures acceleration along three axes (Figure 37-1). The standard unit of acceleration is “g”(short for gravity). 1g is the force pulling down on an object that is at rest at sea level.

The only time an accelerometer will give a reading of 0g is when the device is in free fall (not recommended). Depending on how your iPhone is placed, the 1g of acceleration can be distributed differently across the three axes. An accelerometer can measure both translational acceleration and tilt ...

Get iPhone and iPad App 24-Hour Trainer now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.