自己的导航条与系统UINavigationController的导航条进行自动融合与分离
来源:互联网 发布:重新安装centos u盘 编辑:程序博客网 时间:2024/04/29 09:14
我们在很多APP使用都会遇到,类似的tableview在向上滚动时,会让自己的导航条与系统的UINavigation的titleview进行融合,而当类似的tableview向下滚动时,又会让自己的的导航条与系统的UINavigation的titleview进行分离,另外融合分离会结合一定的滚动或滑动速度,如果慢慢向下滚动或滑动,则不会分离自己的导航条,当速度达到设定的某个值则正式进行分离或融合,另外一般情况下,在分离状态,一般是不可透视的,在融合状态下,是全屏透视的。如以下两图效果
这里的主要实现代码思路如下(这里运用的是通知来实现)
1、在容器中
- (void)viewDidLoad { [super viewDidLoad]; self.automaticallyAdjustsScrollViewInsets = NO; [self setupNavBar]; //其他代码 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideNav) name:NavigationBarHiddenNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showNav) name:NavigationBarShowNotification object:nil];}- (void)setupNavBar{ self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"nav_item_game_icon-1" highImageName:@"nav_item_game_click_icon-1" target:self action:@selector(test)]; self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImageName:@"RandomAcross" highImageName:@"RandomAcrossClick" target:self action:@selector(randomAcross)]; self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MainTitle"]];}- (void)test{ TGFunc}-(void)randomAcross{ TGFunc [[NSNotificationCenter defaultCenter] postNotificationName:AcrossEssenceNotification object:nil userInfo:nil];}-(void) hideNav{ if (self.segmentBarVC.segmentBar.superview != self.segmentBarVC.view) return; self.navigationItem.leftBarButtonItem = nil; self.navigationItem.rightBarButtonItem = nil; self.segmentBarVC.segmentBar.backgroundColor = [UIColor clearColor]; self.navigationItem.titleView = self.segmentBarVC.segmentBar; TGFunc}-(void) showNav{ if (self.segmentBarVC.segmentBar.superview == self.segmentBarVC.view) return; [self setupNavBar]; self.segmentBarVC.segmentBar.backgroundColor = NavTinColor; self.segmentBarVC.segmentBar.frame = CGRectMake(0, NavMaxY, self.segmentBarVC.view.width, TitleVH); [self.segmentBarVC.view addSubview:self.segmentBarVC.segmentBar]; TGFunc}- (void) dealloc{ TGFunc [[NSNotificationCenter defaultCenter] removeObserver:self name:NavigationBarHiddenNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NavigationBarShowNotification object:nil];}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{//只会触发上拉加载更多 if (scrollView.contentOffset.y > _contentOffsetY){//上滚 //TGLog(@"up %f",scrollView.contentOffset.y); if (scrollView.contentOffset.y > 0){ //隐藏,放入nav //通知形式 //TGLog(@"我要隐藏了~~~~~~~~~~~~ %f",scrollView.contentOffset.y); if((scrollView.contentOffset.y - _contentOffsetY) > _contentOffsetSpeed && _contentOffsetSpeed>20){//速度超过20隐藏 //TGLog(@"~~~~~~~~~~~~~~~~~~~~~%f %f",scrollView.contentOffset.y - _contentOffsetY,_contentOffsetSpeed);//滚速递减则不再发通知 [[NSNotificationCenter defaultCenter] postNotificationName:NavigationBarHiddenNotification object:nil userInfo:nil]; } _contentOffsetSpeed = scrollView.contentOffset.y - _contentOffsetY; } }else{ //显示,回归原位 //通知形式 //TGLog(@"dwon %f",scrollView.contentOffset.y); if (scrollView.contentOffset.y > 0){ //TGLog(@"我要显示了^^^^^^^^^^^^^^^^^^^^ %f",scrollView.contentOffset.y); if (_contentOffsetY - scrollView.contentOffset.y > _contentOffsetSpeed && _contentOffsetSpeed>20){//速度超过20显示 //TGLog(@"^^^^^^^^^^^^^^^^^^^^^^^%f %f",_contentOffsetY - scrollView.contentOffset.y,_contentOffsetSpeed); [[NSNotificationCenter defaultCenter] postNotificationName:NavigationBarShowNotification object:nil userInfo:nil]; } _contentOffsetSpeed = _contentOffsetY - scrollView.contentOffset.y; }else if (fabs(scrollView.contentOffset.y) > NavMaxY && fabs(scrollView.contentOffset.y) < NavMaxY+TitleVH){ //TGLog(@"我要显示了^^^^^^^^^^^^^^^^^^^^ %f",scrollView.contentOffset.y); [[NSNotificationCenter defaultCenter] postNotificationName:NavigationBarShowNotification object:nil userInfo:nil]; } } _contentOffsetY = scrollView.contentOffset.y;}
完整的代码请移步到github,如果你觉得赞,请star
https://github.com/targetcloud/baisibudejie
阅读全文
0 0
- 自己的导航条与系统UINavigationController的导航条进行自动融合与分离
- UINavigationController隐藏导航条
- 半透明状态栏与导航条的错位
- iphone导航条的显示与隐藏
- 导航条的设计与实现
- IOS系列——导航条UINavigationController的简单功能
- UINavigationBar 【导航条】自己的见解
- 左侧自动隐藏的导航条
- 关于UINavigationController配置导航条
- IDA的导航条
- 导航条的属性
- 导航条的制作
- 自适应的导航条
- 导航条的制作
- 滑动的导航条
- iOS基础控件-导航栏控制器UINavigationController的UINavigationBar导航条
- iPhone半透明状态栏与导航条错位的解决办法
- iPhone半透明状态栏与导航条错位的解决办法
- 最全三大框架整合(使用映射)——DeptServiceImpl.java
- 计算机视觉领域一些牛人的博客,研究机构网站链接
- 【高级】炼数成金大数据之机器学习视频教程(重点) 11课
- yii 2 框架 save insert update 等操作的细节 详细理解
- Unity特效(1) 梦幻旋屏
- 自己的导航条与系统UINavigationController的导航条进行自动融合与分离
- Vmware安装Nginx
- Request/Response/Cookie/Session中常用方法
- Java学习笔记_17
- C语言程序设计(32)
- 最全三大框架整合(使用映射)——DeptAction.java
- cron表达式笔记
- 如何修改Jtopo中Node和Link的阴影效果
- 最长上升子序列(进阶版)