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 ...
Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android 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.