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
{
_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
- int _lastPosition; //A variable define in headfile
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
- int currentPostion = scrollView.contentOffset.y;
- if (currentPostion - _lastPosition > 25) {
- _lastPosition = currentPostion;
- NSLog(@"ScrollUp now");
- }
- else if (_lastPosition - currentPostion > 25)
- {
- _lastPosition = currentPostion;
- NSLog(@"ScrollDown now");
- }
- }
25 能夠是隨意數字,可依據自己的須要來設定。
UIScrollView滾動時隱藏底部導航欄問題