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

Adding a Gesture Recognizer

If you want to truly understand the iPad user experience, you need to understand the importance of gestures, one of the features that make the use of the device an intimate experience for the user, as I explain in Chapter 1.

UIKit includes gesture recognizers that you can use in your app to make it work the same way as all those fancy apps Apple has come up with. In this section, you’ll use UIKit to add a gesture recognizer to the Main view so that the user can swipe to the left to make the Test Drive view appear.

Adding the gesture recognizer is easy. In RTMasterViewController.m, add the bolded code in Listing 13-1 to viewDidLoad.

Listing 13-1: Adding a Gesture Recognizer

- (void)viewDidLoad

{

[super viewDidLoad];

RTAppDelegate* appDelegate =

[[UIApplication sharedApplication] delegate];

self.title = appDelegate.trip.destinationName;

UIImageView* imageView = [[UIImageView alloc]

initWithImage:[appDelegate.trip destinationImage]];

self.tableView.backgroundView = imageView;

UISwipeGestureRecognizer *swipeGesture =

[[UISwipeGestureRecognizer alloc] initWithTarget:self

action:@selector(handleSwipeGesture:)];

swipeGesture.direction =

UISwipeGestureRecognizerDirectionLeft;

[self.view addGestureRecognizer:swipeGesture];

}

UISwipeGestureRecognizer is a subclass of UIGestureRecognizer — the abstract base class for concrete gesture-recognizer classes. The gesture recognizer does the hard work of recognizing a specific gesture and then ...

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