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

Posted yxysuanfa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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当前是向上滑动还是向下滑动:

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

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

以上是关于UIScrollView滚动时隐藏底部导航栏问题的主要内容,如果未能解决你的问题,请参考以下文章

iOS:滚动表格视图时隐藏和显示自定义导航栏

UIScrollView 在导航和状态栏下方移动

往下滚动,导航栏隐藏

UIScrollView 需要根据 UILabel 大小进行扩展但保持底部标签栏

隐藏导航栏时显示状态栏

UIScrollView 不垂直滚动(我有一个底栏视图)