一、新建一个控制器,继承UINavigationController
二、右滑手势代码
06 | [self addSwipeRecognizer]; |
10 | - ( void )addSwipeRecognizer |
13 | UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector( return )]; |
16 | swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight; |
19 | swipeRecognizer.numberOfTouchesRequired = 1; |
22 | [[self view] addGestureRecognizer:swipeRecognizer]; |
29 | if (self.viewControllers.count <= 1) return ; |
32 | [self popToRootViewControllerAnimated:YES]; |
三、然后只要在AppDelegate中将自定义的导航控制器设置为根控制器
01 | #import "AppDelegate.h" |
02 | #import "MainViewController.h" |
03 | #import "FirstViewController.h" |
05 | @implementation AppDelegate |
07 | - ( BOOL )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions |
09 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
12 | FirstViewController *first = [[FirstViewController alloc] initWithNibName:@ "FirstViewController" bundle:nil]; |
15 | MainViewController *main = [[MainViewController alloc] initWithRootViewController:first]; |
18 | self.window.rootViewController = main; |
20 | self.window.backgroundColor = [UIColor whiteColor]; |
21 | [self.window makeKeyAndVisible]; |
四、统一成一个导航控制器可以统一一些东西
1、统一导航栏样式
1 | self.navigationBar.barTintColor = [UIColor whiteColor]; |
2、若在控制器之间跳转时需要做一些事情,可在自定义的控制器里添加下面两个方法
02 | - ( void )pushViewController:(UIViewController *)viewController animated:( BOOL )animated |
07 | [super pushViewController:viewController animated:animated]; |
11 | - (UIViewController *)popViewControllerAnimated:( BOOL )animated |
16 | return [super popViewControllerAnimated:animated]; |