O'Reilly logo

iPad Application Development For Dummies, 3rd Edition by Neal Goldstein

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

Implementing the testDrive Method

In Chapter 9, I tell you how to create an action for the Test Drive button using Interface Builder, which generated a method stub for you. Now it’s time to fill that stub with code.

Add the bolded code in Listing 10-2 to the testDrive: method in TestDriveController.m. I’m also having you add the stubs for code you’ll be adding later so that you can run your program before you’re completely finished with the back and forth of the animation.

Listing 10-2: Updating testDrive: to Move the Car Up the Screen

- (IBAction)testDrive:(id)sender {

CGPoint center = CGPointMake(car.center.x,

self.view.frame.origin.y + car.frame.size.height/2);

[UIView animateWithDuration:3 animations:^ {

car.center = center;

}

completion:^(BOOL finished){

[self rotate];

}];

}

- (void)rotate {

}

- (void)returnCar {

}

- (void)continueRotation {

}

Now, run your program and click or touch the Test Drive button. You’ll see your car move up the screen. You’re on your way!

Looking more closely at Listing 10-2, you see that you start by creating the coordinate (CGPoint) of where you would like the car to end up.

remember.eps A car is just another view.

CGPoint center = CGPointMake(car.center.x,

self.view.frame.origin.y + car.frame.size.height/2);

You use the center and frame properties primarily for manipulating the view. If you’re changing only the position of the view (and not ...

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