8. The Accelerometer

One of the flashiest features of the iPhone 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 the 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 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. HypnosisView

image

Setting Up the Accelerometer

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

Get iPhone Programming: The Big Nerd Ranch Guide 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.