IOS系列—— UINavigationController隐藏后手势返回不可用
来源:互联网 发布:yum wget 编辑:程序博客网 时间:2024/06/05 07:57
1、隐藏导航栏
1)、
self.navigationController.navigationBar.alpha = 0;等同于
nav.navigationBar.hidden = YES;这种方法的原理是 navBar的本质是一个view 可以直接设置隐藏和透明度,但是他的位置没变 只是看不到了而已
而且用这行代码吧导航条隐藏掉 手势返回是依然可用的
2)、
nav.navigationBarHiidden = YES;或者
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden animated:YES];这个是系统支持的nav的方法,但是这个方法的弊端是手势不可返回
如果要继续支持手势的话,需要手动添加一下方法,并添加代理
self.navigationController.interactivePopGestureRecognizer.delegate = self; self.navigationController.interactivePopGestureRecognizer.enabled = YES;
2、导航栏中部分viewController隐藏导航栏
效果可参照支付宝首页点击之后,
在需要隐藏的导航栏的viewController中添加
-(void)viewWillAppear:(BOOL)animated{ [super <span style="font-family: Arial, Helvetica, sans-serif;">viewWillAppear:animated</span>]; [self.navigationController setNavigationBarHidden:YES animated:YES];}-(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:YES];}为什么要在will的方法添加而不是在did方法里面去添加?
原因在于:如果隐藏的viewController是nav的最后一个,ok,是没有问题的,但是如果隐藏了nav的VieController后面还有ViewController,那么就出现了问题,具体的可以自己去测试
更多请参考:iOS导航栏的正确隐藏方式
3.获取已存在的导航条
在项目中 很多时候 会自定义导航条
[[[UIApplication sharedApplication].windows firstObject] rootViewController]
UIViewController *controller = (UIViewController *)[[[UIApplication sharedApplication] keyWindow] rootViewController]; UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:view]; nav.navigationBar.hidden = YES;
在导航条可手势返回的前提下
控制某一个页面不可手势返回
待验证
当从控制器A push到控制器B,我们返回控制器A,除了使用按钮返回
还可以使用ios7出来的向右滑动,返回控制器A
文档中是这样定义的:
@property(nullable, nonatomic, weak) id<UINavigationControllerDelegate> delegate;@property(nullable, nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
我们在控制器B中的viewDidLoad中
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; // 手势有效设置为YES 无效为NO self.navigationController.interactivePopGestureRecognizer.delegate = self; // 手势的代理设置为self }
但是当回到控制器A中时,再想push到控制器B,就会出现卡屏,不会动的现象,因为rootView也会有向右滑动返回的问题,要解决这个问题,我们只需在控制器A的viewDidAppear中设置,interactivePopGestureRecognizer为NO:
-(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; }}
这样即可以保证再B中向右滑返回A动后再次pushB时不会卡在A界面。
0 0
- IOS系列—— UINavigationController隐藏后手势返回不可用
- uinavigationcontroller手势返回
- iOS UINavigationController的iOS 7的手势滑动返回功能
- UINavigationController返回手势失效问题
- UINavigationController返回手势失效问题
- UINavigationController返回手势失效问题
- UINavigationController返回手势失效问题
- UINavigationController返回手势失效问题
- UINavigationController返回手势失效问题
- IOS 开发笔记——自定义导航栏返回键后如何恢复系统默认返回手势
- iOS UINavigationController 返回总结
- IOS系列——导航条UINavigationController的简单功能
- iOS开发UINavigation系列四——导航控制器UINavigationController
- iOS——UINavigationController
- iOS 页面跳转后去掉返回按钮和返回手势
- iOS自定义返回按钮(不影响返回手势)
- IOS push后隐藏返回按钮
- IOS开发笔记——禁用手势滑动返回功能
- Path Sum
- UVA10917 路径统计
- 数据挖掘实验(SAS)聚类
- LeetCode 011. Container With Most Water
- SoapObject result=(SoapObject)envelope.getResponse(); 这个有时候会出现转换异常。
- IOS系列—— UINavigationController隐藏后手势返回不可用
- 黑马程序员——一个古老的悖论
- c++中的虚函数
- oracle中的decode的使用
- linux机器间文件拷贝
- 剑指offer面试题4—替换空格
- Web开发基本准则
- 求职面试的时候如何谈薪酬待遇
- 始终都无法删除Cookie