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 ...
Get iPad Application Development For Dummies, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.