1. 程式人生 > >UIScrollView滾動時隱藏底部導航欄問題

UIScrollView滾動時隱藏底部導航欄問題

art side silver iscroll trac import isp tom 底部導航

- (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 plaincopy
  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 能夠是隨意數字,可依據自己的須要來設定。

UIScrollView滾動時隱藏底部導航欄問題