Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

#3. Accelerometer

One of the most versatile pieces of hardware in iOS devices is the accelerometer. The accelerometer allows the device to detect acceleration and the pull of gravity along three axes. With just a few lines of code, you can tell whether the device is right-side up, upside down, laying flat on a table, etc. You can even detect how quickly the device is changing direction.

All you need is the UIAccelerometer

Getting orientation information from your device is straightforward. There’s a shared UIAccelerometer instance you can access. Like many other iOS classes, the UAccelerometer has a delegate protocol, UIAccelerometerDelegate, that declares a single method for receiving acceleration information. The class you want to receive that acceleration information should conform to the UIAccelerometerDelegate protocol and implement didAccelerate: method.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial