Skip to Content
Basic Sensors in iOS
book

Basic Sensors in iOS

by Alasdair Allan
July 2011
Beginner to intermediate
108 pages
2h 29m
English
O'Reilly Media, Inc.
Content preview from Basic Sensors in iOS

Accessing the Gyroscope

Let’s go ahead and implement a simple view-based application to illustrate how to use the gyroscope on its own before looking again at Core Motion and CMDeviceMotion. Open Xcode and start a new View-based Application iPhone project and name it “Gyroscope” when prompted for a filename.

Since we’ll be making use of the Core Motion framework, the first thing we need to do is add it to our new project. Click on the project file at the top of the Project navigator window on the right in Xcode, select the Target and click on the Build Phases tab, click on the Link with Libraries drop down and click on the + button to open the file pop-up window. Select CoreMotion.framework from the list of available frameworks and click the Add button.

Now go ahead and click on the GyroscopeViewController.xib file to open it in Interface Builder. As you did for the accelerometer back in Chapter 4, you’re going to build a simple interface to report the raw gyroscope readings. Go ahead and drag and drop three UIProgressView from the Object Library into the View window, then add two UILabel elements for each progress bar: one to hold the X, Y, or Z label and the other to hold the rotation measurements. After you do that, the view should look something a lot like Figure 6-1.

The Gyroscope UI

Figure 6-1. The Gyroscope UI

Go ahead and close the Utilities panel and click to open the Assistant Editor. Then Control-Click ...

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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

iOS 7 Programming Cookbook

iOS 7 Programming Cookbook

Vandad Nahavandipoor
iOS 4 Programming Cookbook

iOS 4 Programming Cookbook

Vandad Nahavandipoor
iPhone and iPad App 24-Hour Trainer

iPhone and iPad App 24-Hour Trainer

Abhishek Mishra, Gene Backlin

Publisher Resources

ISBN: 9781449309480Errata Page