iOS-隐藏Navigationbar【导航栏无缝圆滑的隐藏】
1.ViewController
.m
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"隐藏导航栏";
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor lightGrayColor];
button.frame = CGRectMake(, , , );
[button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
self.navigationController.delegate = self;
}
- (void)buttonClick{
///跳转到KKViewController
[self performSegueWithIdentifier:@"pusht" sender:nil];
}
头部代理
@interface ViewController ()<UINavigationControllerDelegate>
代理方法
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[self.navigationController setNavigationBarHidden: [self hiddenBarVc: viewController] animated: animated];
}
- (BOOL)hiddenBarVc:(UIViewController *)viewController {
BOOL needHideNaivgaionBar = NO;
if ([viewController isKindOfClass: [KKViewController class]]) {
needHideNaivgaionBar = YES;
}
return needHideNaivgaionBar;
}
2.KKViewController(目标ViewController)
新建一个KKViewController
.h
@property (nonatomic,strong) id popDelegate;
.m
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"第二个页面";
[self popSet];
}
- (void)popSet{
_popDelegate = self.navigationController.interactivePopGestureRecognizer.delegate;
SEL action = NSSelectorFromString(@"handleNavigationTransition:");
UIPanGestureRecognizer *popPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.popDelegate action:action];
popPanGesture.maximumNumberOfTouches = ;
popPanGesture.delegate = self;
[self.view addGestureRecognizer: popPanGesture];
}
头部代理
@interface KKViewController ()<UIGestureRecognizerDelegate>
手势代理方法
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer{
///【下面两个方法写一个】
///全屏拖动
CGPoint tragPoint = [gestureRecognizer translationInView:gestureRecognizer.view];
if (tragPoint.x <= ){
return NO;
}
else{
if (self.navigationController.viewControllers.count <= ){
return NO;
}
else{
return YES;
}
}
// ///局部允许拖动
// CGPoint tragPoint = [gestureRecognizer locationInView:gestureRecognizer.view];
// NSLog(@"x=%f;y=%f",tragPoint.x,tragPoint.y);
// if (tragPoint.x > 60){///拖动的范围
// return NO;
// }
// else{
// if (self.navigationController.viewControllers.count <= 1) {
// return NO;
// }
// else{
// return YES;
// }
// }
}
效果图

延伸
最后再推荐一个Git开源,覆盖全屏pop手势 FDFullscreenPopGesture,它里面也实现了隐藏导航栏的功能,很流畅!
iOS-隐藏Navigationbar【导航栏无缝圆滑的隐藏】的更多相关文章
- 【iOS开发-22】navigationBar导航栏,navigationItem建立:获取导航栏中的基本文本和button以及各种跳跃
(1)navigationBar导航栏可以被看作是self.navigationController一个属性导航控制器,它可以由点直接表示self.navigationController.navig ...
- iOS系统中导航栏的转场解决方案与最佳实践
背景 目前,开源社区和业界内已经存在一些 iOS 导航栏转场的解决方案,但对于历史包袱沉重的美团 App 而言,这些解决方案并不完美.有的方案不能满足复杂的页面跳转场景,有的方案迁移成本较大,为此我们 ...
- 【转】iOS中设置导航栏标题的字体颜色和大小
原文网址:http://www.360doc.com/content/15/0417/11/20919452_463847404.shtml iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参 ...
- iOS中设置导航栏标题的字体颜色和大小
iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参考下. 在平时开发项目的时候,难免会遇到修改导航栏字体大小和颜色的需求,一般使用自定义视图的方法,其实还存在一种方法. 方法一:(自定义视图的 ...
- unity 显示、隐藏Android导航栏
1.下面的返回.home栏可用Screen.fullScreen控制 2.导航栏的显示和隐藏用下面代码控制 private AndroidJavaObject currentActivity { ge ...
- 通过HTML+CSS+JavaScript实现鼠标移动到页面顶部导航栏出现,如果移出导航栏3秒又隐藏起来,而且不受滚动条影响(二)
通过HTML+CSS+JavaScript实现鼠标移动到页面顶部导航栏出现,如果移出导航栏3秒又隐藏起来,而且不受滚动条影响(二) 效果:默认一直隐藏导航栏,当滚动条滚到超过300px按钮出现,点击回 ...
- iOS navigationBar导航栏底部与self.view的分界线的隐藏
ios开发中经常碰到各种需求,比如要求导航栏的颜色和self.view的颜色一样,当我们直接设置navigationBar的颜色和view一样时,我们会发现navigationBar还会有一条分割线留 ...
- iOS UITableView表视图滚动隐藏UINavigationController导航栏
UITableView 继承于UIScrollView 所以UIScrollView 的代理方法相同适用于UITableView 中 隐藏导航栏的方法为: self.navigationControl ...
- iOS:自定义导航栏,随着tableView滚动显示和隐藏
自定义导航栏,随着tableView滚动显示和隐藏 一.介绍 自定义导航栏是APP中很常用的一个功能,通过自定义可以灵活的实现动画隐藏和显示效果.虽然处理系统的导航栏也可以实现,但是这个是有弊端的,因 ...
随机推荐
- 最短路(spfa)
http://acm.hdu.edu.cn/showproblem.php?pid=2544 最短路 Time Limit: 5000/1000 MS (Java/Others) Memory ...
- python内建函数isinstance基础用法
语法:isinstance(object,type) 作用:来判断一个对象是否是一个已知的类型. 其第一个参数(object)为对象,第二个参数(type)为类型名(int...)或类型名的一个 ...
- 如何在vue中使用sass
使用sass,我们需要安装sass的依赖包 npm install --save-dev sass-loader //sass-loader依赖于node-sass npm install --sav ...
- git上传项目全部流程
一.下载git 进入网址:https://git-scm.com/downloads: 点击中的Download 2.16.0 for Windows; 在中选择蓝色字段点击,根据电脑64或32位选择 ...
- 使用bat将优盘中的dig加到系统环境变量
第一次使用bat批处理,记录下,方便查阅. @echo off::当前盘符set curPath=%cd%set digPath ="%curPath%tool\dig"set P ...
- 我是如何将网站全站启用Https的?-记录博客安装配置SSL证书全过程
评论» 文章目录 为什么要Https 如何选择Https 安装部署SSL证书 平滑过渡Https 搜索引擎的响应 启用Https小结 正如大家所看到的,部落全站已经启用了Https访问了,连续几天 ...
- 怎么获取smtp服务器用户帐号和密码
在OE里工具-帐户..-添加-邮件 打开选项卡,依次填好,昵称,按下一步,邮箱地址,按下一步,填POP和SMTP服务器地址,按下一步,按用户名和密码,再按下一步就设置好了.有些邮件服务器在发信的时候, ...
- 阿里大鱼 阿里云api
阿里短信服务API接入指南及示例 : https://yq.aliyun.com/articles/59928 =========================================== ...
- eclipse中git解决冲突
摘录自http://blog.csdn.net/rosten/article/details/17068285 1. 工程->Team->同步 2.从远程pull至本地,就会出现如下内容 ...
- Hyperledger Fabric CouchDB as the State Database
使用CouchDB作为状态数据库 状态数据库选项 状态数据库包括LevelDB和CouchDB.LevelDB是嵌入在peer进程中的默认键/值状态数据库,CouchDB是一个可选的外部状态数据库.与 ...