Measuring Device Motion
Let’s go ahead and build a similar application to the one above, but
this time reporting the data exposed by the CMDeviceMotion object:
CMAttitude *attitude = motionData.attitude; CMAcceleration gravity = motionData.gravity; CMAcceleration userAcceleration = motionData.userAcceleration; CMRotationRate rotate = motionData.rotationRate;
Open Xcode and start a new iPhone project, select a View-based
Application template, and name the project “Motion” when prompted for a
filename. As before, import the Core Motion framework into the project and
then click on the MotionViewController.xib file to open it in
Interface Builder, and then proceed to drag-and-drop UIProgressBar and UILabel elements into your View in a similar
manner as you did for the Gyroscope application earlier in the chapter.
You’ll need labels for the yaw, pitch and roll values, along with progress
bars and labels for the user acceleration, gravity and rotation
values.
Once you’ve done this, go ahead and connect the various bars and
labels as IBOutlet using the Assistant
Editor into the MotionViewController.h interface file as in
Figure 6-5.

Figure 6-5. The Motion application UI with the IBOutlet connected in Interface Builder to the MotionViewController.h interface file
Once you’ve done this, save your changes and open up the MotionViewController.h interface file in the Standard Editor. Go ahead and ...
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.
Read now
Unlock full access