Skip to Main Content
Beginning iOS 4 Application Development
book

Beginning iOS 4 Application Development

by Wei-Meng Lee
October 2010
Beginner content levelBeginner
655 pages
14h 9m
English
Wrox
Content preview from Beginning iOS 4 Application Development

Chapter 15. Accessing the Accelerometer

WHAT YOU WILL LEARN IN THIS CHAPTER

  • How to obtain accelerometer data from your iPhone

  • How to detect shakes to your device

iPhone's built-in accelerometer enables your program to detect the orientation of the device and adapt the content to suit the new orientation. For example, when you rotate your device sideways, the Safari Web browser automatically switches the screen to landscape mode to provide a wider viewing space.

In this chapter, you learn how to access the accelerometer and use the Shake API to detect shakes to your iPhone.

Using the Accelerometer

The accelerometer in iPhone measures the acceleration of the device relative to freefall. A value of 1 indicates that the device is experiencing 1 g of force exerted on it (1 g of force being the gravitational pull of the earth, which your device experiences when it is stationary). The accelerometer measures the acceleration of the device in three different axes: x, y and z. Figure 15-1 shows the different axes measured by the accelerometer.

Figure 15-1

Figure 15.1. Figure 15-1

Table 15-1 shows example readings of the three axes when the device is in the various positions. Bear in mind that you won't see the exact same values as these, because they are always fluctuating due to the accelerometer's sensitivity.

Table 15.1. Example Readings of the X, Y, and Z Axes

POSITION

X

Y

Z

Vertical upright position

0.0

−1.0

0.0

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning iOS 5 Application Development

Beginning iOS 5 Application Development

Wei-Meng Lee

Publisher Resources

ISBN: 9780470918029Purchase book