UIScrollView滚动时隐藏底部导航栏问题

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

NSLog(@"開始滚动");

int currentPostion = scrollView.contentOffset.y;

if (currentPostion -
_lastPosition > 20  && currentPostion >0) {

_lastPosition = currentPostion;

NSLog(@"ScrollUp now");

self.tabBarController.tabBar.hidden
=YES;

[self.navigationControllersetNavigationBarHidden:YESanimated:YES];

}

else
if ((_lastPosition - currentPostion >20) && (currentPostion  <= scrollView.contentSize.height-scrollView.bounds.size.height-20)
)

{

_lastPosition = currentPostion;

NSLog(@"ScrollDown now");

self.tabBarController.tabBar.hidden
=NO;//隐藏时,没有动画效果

[self.navigationControllersetNavigationBarHidden:NOanimated:YES];

}

}

转载自:http://blog.csdn.net/caryaliu/article/details/7907196

自:在我的project中,我是把  _lastPosition = 0。   然后把那个 25 改成了 160

有时候我们须要检測当前UIScrollView的滑动方向来做出对应的处理,能够借助UIScrollView的delegate函数来实现。 以下的样例能够检測到UIScrollview当前是向上滑动还是向下滑动:

[cpp] view
plain
copy

  1. int _lastPosition;    //A variable define in headfile
  2. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  3. int currentPostion = scrollView.contentOffset.y;
  4. if (currentPostion - _lastPosition > 25) {
  5. _lastPosition = currentPostion;
  6. NSLog(@"ScrollUp now");
  7. }
  8. else if (_lastPosition - currentPostion > 25)
  9. {
  10. _lastPosition = currentPostion;
  11. NSLog(@"ScrollDown now");
  12. }
  13. }

25 能够是随意数字,可依据自己的须要来设定。

时间: 2024-08-10 00:06:49

UIScrollView滚动时隐藏底部导航栏问题的相关文章

隐藏底部导航栏tabbar

在有tabbarcontroller时,A界面push到B界面想隐藏底部tabbar,从B界面返回A后再显示tabbar.那么在控制器A中可以设置 -(void)clickTheSettingBtn{ ControllerB *vcB = [[ControllerB alloc]init]; //在跳转之前设置为YES self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vcB an

tableView等滚动视图滚动时收缩上下导航栏与标签栏

代码如下,今天有点忙,不想细说了,看不明白可以联系我 // // LQXViewController.m // LQXCallBackBar // // Created by 刘祺旭 on 15/4/27. // Copyright (c) 2015年 CSDN探花花花. All rights reserved. // #import "LQXViewController.h" #define LQXWidth self.view.bounds.size.width #define L

ionic2 跳转子页面隐藏底部导航栏

在需要跳转页面的.ts文件中写入以下代码 引入App类 import { App } from 'ionic-angular'; 声明初始化app对象 constructor(private app:App) {} 从根页面跳转 this.app.getRootNav().push(nextPage);

iOS UITableView表视图滚动隐藏UINavigationController导航栏

UITableView 继承于UIScrollView 所以UIScrollView 的代理方法同样适用于UITableView 中 隐藏导航栏的方法为: self.navigationController.navigationBar.hidden = YES; 所以我们只有通过滚动的代理方法监测滚动视图的滚动方向来控制导航栏显示还是隐藏即可: 通过实现UIScrollView的代理方法来操作: 方式如下: // 滑动scrollView,并且手指离开时执行.一次有效滑动,只执行一次. // 当

底部导航栏使用BottomNavigationBar

1.github地址 https://github.com/zhouxu88/BottomNavigationBar 2.基本使用 2,1添加依赖 implementation 'com.ashokvarma.android:bottom-navigation-bar:2.0.5' 2.2布局中使用 <com.ashokvarma.bottomnavigation.BottomNavigationBar android:layout_width="match_parent" an

实现底部导航栏

许多的App都使用底部导航栏来实现导航功能,我们可以使用RadioGroup+RadioButton的形式或者直接Button数组的方式实现,而谷歌官方提供了FragmentTabHost来方便快捷实现底部导航栏. android.support.v4.app.FragmentTabHost 主要代码: fragmentTabHost.setup(this, getSupportFragmentManager(), R.id.layout_content); for (int i = 0; i 

Android实习札记(5)---Fragment之底部导航栏的实现

Android实习札记(5)---Fragment之底部导航栏的实现 --转载请注明出处:coder-pig 在Part 4我们回顾了一下Fragment的基本概念,在本节中我们就来学习Fragment应用的简单例子吧! 就是使用Fragment来实现简单的底部导航栏,先贴下效果图: 看上去很简单,实现起来也是很简单的哈!那么接着下来就看下实现的流程图吧: 实现流程图: 看完流程图是不是有大概的思路了,那么接着就开始代码的编写吧: 代码实现: ①先写布局,布局的话很简单,一个FrameLayou

移动端底部导航栏固定——兼容IOS

问题:移动端前端底部导航栏设计 兼容安卓下的各种浏览器和IOS自带的Safari,但是不兼容苹果下的 钉钉. 具体代码格式: <body> <!-- 头部导航栏 --> <div class="header">内容</div> <!-- 内容 --> <div class="content">内容</div> <!-- 底部导航栏 --> <div class=&q

Android仿小米商城底部导航栏之二(BottomNavigationBar、ViewPager和Fragment的联动使用)

简介 在前文<Android仿小米商城底部导航栏(基于BottomNavigationBar)>我们使用BottomNavigationBar控件模仿实现了小米商城底部导航栏效果.接下来更进一步的,我们将通过BottomNavigationBar控件和ViewPager空间的联动使用来实现主界面的滑动导航. 导航是移动应用最重要的方面之一,对用户体验是良好还是糟糕起着至关重要的作用.好的导航可以让一款应用更加易用并且让用户快速上手.相反,糟糕的应用导航很容易让人讨厌,并遭到用户的抛弃.为了打造