8The Accelerometer

One of the flashiest features of iOS is the accelerometer. The accelerometer detects the device’s real-world orientation by tracking the force of the earth’s gravity on its X, Y, and Z axes. You can also use accelerometer data to detect changes in the device’s velocity.

In this chapter, you are going to use the accelerometer to skew the center of the HypnosisView according to the device’s orientation: when the user tilts the phone, the center will slide in the direction of the tilt, as shown in Figure 8.1.

Figure 8.1  HypnoTime, tilted

HypnoTime, tilted

Setting Up the Accelerometer

To receive accelerometer data, your application needs to get ...

Get iOS Programming: The Big Nerd Ranch Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.