Accelerometer Support

The accelerometer built into the iPhone has proven to be a very popular feature, especially for game developers. The accelerometer lets the entire device be used as an input device, with its orientation and movement in space transmitted to an application for custom handling. The ability to tilt and shake the device and control applications opens new possibilities for application developers. The user experience concerns for games are somewhat different from those for productivity, utility, or media-based applications. In most cases, accelerometer support for the latter types of applications is a novelty addition. If your application uses the accelerometer as the sole means of input for any piece of functionality, you may be alienating users who aren’t in a position to—or who simply don’t wish to—shake and twist their phone around to use a piece of software.

Accessing the accelerometer is a very simple process. The UIAccelerometer class represents access to acceleration events. You can grab an instance of UIAccelerometer with the singleton method sharedAccelerometer.

The instance requires a delegate assignment. The UIAccelerometerDelegate interface defines a single method that must be implemented to handle acceleration events. The method signature is accelerometer:didAccelerate:. Keep in mind that the UIAccelerometer construction method uses a singleton instance, which means there is always only one instance of the accelerometer in memory. As a side effect, ...

Get Programming the iPhone User Experience 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.