How can I switch views vertically using swipe gestures ?
Certainly! Just set your viewController to be the UIGestureRecognizerDelegate and declare UISwipeGestureRecognizer *swipeLeftRecognizer; (also retain and synthesize). Then, in the implementation, set up the recognizers with
UIGestureRecognizer *recognizer;
// RIGHT SWIPE
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSwipeFrom:)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
// LEFT SWIPE
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
self.swipeLeftRecognizer = (UISwipeGestureRecognizer *)recognizer;
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeftRecognizer];
self.swipeLeftRecognizer = (UISwipeGestureRecognizer *)recognizer;
[recognizer release];
Then trigger the actions you want with the method
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
// load a different viewController
} else {
// load an even different viewController
}
}
What you do here is specific to your app. You can switch the tabBar selection, jump through a navigationController, present a different view modally, or just do a simple slide in transition.