O'Reilly logo

Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android by Michael Eierman, Jakob Iversen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Core Motion for Accelerometer Data

Included in iOS is a framework called Core Motion, which provides access to several sensors, including gyroscope, magnetometer, and accelerometer. In this section, you learn how to access the data from the accelerometer to move an object around the screen of the device by tilting the device.

The accelerometer provides data about the velocity that the device is moving in in three dimensions. If the device is held vertically in front of you, the X-axis measures movement left and right, the Y-axis measures movement away from and toward you, and the Z-axis measures movement up and down. When working with the accelerometer, you create an object of the class CMMotionManager. It’s important to create only a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required