统一添加导航控制器右滑返回手势
2014-06-03 11:48
183 查看
一、新建一个控制器,继承UINavigationController
二、右滑手势代码
三、然后只要在AppDelegate中将自定义的导航控制器设置为根控制器
四、统一成一个导航控制器可以统一一些东西
1、统一导航栏样式
2、若在控制器之间跳转时需要做一些事情,可在自定义的控制器里添加下面两个方法
二、右滑手势代码
01 | - ( void )viewDidLoad |
02 | { |
03 | [super viewDidLoad]; |
04 |
05 | // 添加右滑手势 |
06 | [self addSwipeRecognizer]; |
07 | } |
08 |
09 | #pragma mark 添加右滑手势 |
10 | - ( void )addSwipeRecognizer |
11 | { |
12 | // 初始化手势并添加执行方法 |
13 | UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector( return )]; |
14 |
15 | // 手势方向 |
16 | swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight; |
17 |
18 | // 响应的手指数 |
19 | swipeRecognizer.numberOfTouchesRequired = 1; |
20 |
21 | // 添加手势 |
22 | [[self view] addGestureRecognizer:swipeRecognizer]; |
23 | } |
24 |
25 | #pragma mark 返回上一级 |
26 | - ( void ) return |
27 | { |
28 | // 最低控制器无需返回 |
29 | if (self.viewControllers.count <= 1) return ; |
30 |
31 | // pop返回上一级 |
32 | [self popToRootViewControllerAnimated:YES]; |
33 | } |
01 | #import "AppDelegate.h" |
02 | #import "MainViewController.h" |
03 | #import "FirstViewController.h" |
04 |
05 | @implementation AppDelegate |
06 |
07 | - ( BOOL )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions |
08 | { |
09 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
10 |
11 | // 初始化一个控制器 |
12 | FirstViewController *first = [[FirstViewController alloc] initWithNibName:@ "FirstViewController" bundle:nil]; |
13 |
14 | // 初始化自定义的导航控制器 |
15 | MainViewController *main = [[MainViewController alloc] initWithRootViewController:first]; |
16 |
17 | // 把自定义的导航控制器设置为根控制器 |
18 | self.window.rootViewController = main; |
19 |
20 | self.window.backgroundColor = [UIColor whiteColor]; |
21 | [self.window makeKeyAndVisible]; |
22 | return YES; |
23 | } |
1、统一导航栏样式
1 | self.navigationBar.barTintColor = [UIColor whiteColor]; |
01 | #pragma mark push方法 |
02 | - ( void )pushViewController:(UIViewController *)viewController animated:( BOOL )animated |
03 | { |
04 | // do something you want |
05 | ... |
06 |
07 | [super pushViewController:viewController animated:animated]; |
08 | } |
09 |
10 | #pragma mark pop方法 |
11 | - (UIViewController *)popViewControllerAnimated:( BOOL )animated |
12 | { |
13 | // 比如停止网络请求 |
14 | ... |
15 |
16 | return [super popViewControllerAnimated:animated]; |
17 | } |
相关文章推荐
- 导航控制器自定义返回控件及手势失效问题
- 关于导航控制器使用手势滑动返回上一个界面中途导航条消失的解决办法
- 导航控制器自定义返回控件及手势失效问题
- ios 自定义导航栏,开启侧滑返回手势
- Swift - 导航控制器(navigationController)全屏滑动返回功能实现
- ios 添加全屏返回手势
- IOS开发 导航控制器全屏滑动返回效果
- 实际iOS编程中遇到的自定义导航栏按钮,导致手势返回失效的解决方法
- iOS开发之自定义导航栏返回按钮右滑返回手势失效的解决
- iOS 导航控制器返回栈中的某一控制器
- IOS 开发笔记——自定义导航栏返回键后如何恢复系统默认返回手势
- 02---按钮的设置 控制器拥有导航栏包装一层导航控制器 添加子控制器 UIBarButtonItem导航按钮 设置导航栏UINavigationBar主题 设置状态栏样式
- iOS开发之自定义导航栏返回按钮右滑返回手势失效的解决
- ios 8行代码教你搞定导航控制器全屏滑动返回效果
- 导航控制器里边添加UIScrollView (automaticallyAdjustsScrollViewInsets)
- iOS开发之自定义导航栏返回按钮右滑返回手势失效的解决
- 谈一谈拦截导航控制器返回事件(下)——AOP
- 从当前带导航的控制器返回到前面的某个控制器
- iOS自定义导航控制器侧滑返回的多种实现方法
- 自定义导航控制器返回按钮以及隐藏返回按钮的文字