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

时间:2025-02-28 13:06:08

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

NSLog(@"開始滚动");

int currentPostion = scrollView.contentOffset.y;

if (currentPostion -
  && currentPostion >) {

_lastPosition = currentPostion;

NSLog(@"ScrollUp now");

self.tabBarController.tabBar.hidden
=YES;

[self.navigationControllersetNavigationBarHidden:YESanimated:YES];

}

else
) && (currentPostion  <= scrollView.)
)

{

_lastPosition = currentPostion;

NSLog(@"ScrollDown now");

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

[self.navigationControllersetNavigationBarHidden:NOanimated:YES];

}

}

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

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

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

  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 能够是随意数字,可依据自己的须要来设定。