O'Reilly logo

Beginning iOS 5 Application Development by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

VISUALIZING THE SENSOR DATA

Printing out the raw values of the gyroscope and accelerometer data is not very exciting. Instead, the following Try It Out shows you how to modify the application so that you can use the gyroscope data to move a soccer ball on the screen.

TRY IT OUT: Visualizing the Gyroscope Data

  1. Using the same project created in the previous section, add the CoreGraphics.framework to the project (see Figure 15-6).
  2. Add an image of a soccer ball to the Supporting Files folder, as shown in Figure 15-7.

    image

    FIGURE 15-6

    image

    FIGURE 15-7

  3. Select the GyroscopeViewController.xib file to edit it in Interface Builder.
  4. Add an ImageView to the View window and set its Image attribute to ball.png (see Figure 15-8).

    image

    FIGURE 15-8

  5. In the GyroscopeViewController.h file, add the following code in bold:
    #import <UIKit/UIKit.h=
    #import <CoreMotion/CoreMotion.h=
    
    @interface GyroscopeViewController : UIViewController
    {
        IBOutlet UITextField *txtRoll;
        IBOutlet UITextField *txtPitch;
        IBOutlet UITextField *txtYaw;
    
        IBOutlet UITextField *txtX;
        IBOutlet UITextField *txtY;
        IBOutlet UITextField *txtZ;
    
        CMMotionManager *mm;
    
        IBOutlet UIImageView *imageView;
        CGPoint delta;
        CGPoint translation;
        float ballRadius; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required