In this tutorial, I will show you how to swipe left to right and vice versa in a tab bar. See the code below.
In the class that set on a tab index: 0, we just name it FirstClass.h and FirstClass.m on its viewdidload method. Add this code below.
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rates)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
And add this method
- (void)rates{
self.tabBarController.selectedIndex = 1;
[self.tabBarController.selectedViewController.navigationController popViewControllerAnimated:YES];
}
In the class that set on a tab index: 1, we just name it SecondClass.h and SecondClass.m on its viewdidload method. Add this code below.
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rates)];
swipeRight.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRight];
And add this method
- (void)rates{
self.tabBarController.selectedIndex = 0;
[self.tabBarController.selectedViewController.navigationController popViewControllerAnimated:YES];
}
Assuming that we have only 2 tabs in our tab bar. Note this will work on the class that extends UIViewController and not working on UITableViewCell.
That's it.
No comments:
Post a Comment