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

来源:互联网 发布:阿里云域名未备案 编辑:程序博客网 时间:2024/06/05 18:51

- (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];

        

    }

    elseif ((_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

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

有时候我们需要检测当前UIScrollView的滑动方向来做出相应的处理,可以借助UIScrollView的delegate函数来实现, 下面的例子可以检测到UIScrollview当前是向上滑动还是向下滑动:

[cpp] view plaincopy
  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 可以是任意数字,可根据自己的需要来设定。

0 0
原创粉丝点击