当前位置:   article > 正文

如何判断uiscrollview是向上滚动还是向下滚动_swiftui监听scrollviewreader向下滚动

swiftui监听scrollviewreader向下滚动

自:我的真实的已经实现的,这个可以当到达顶部或底部时不会反弹,PERFERCT!!!

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    int currentPostion = scrollView.contentOffset.y;

    if (currentPostion - _lastPosition > 20  && currentPostion > 0) {        //这个地方加上 currentPostion > 0 即可)

        _lastPosition = currentPostion;

        NSLog(@"ScrollUp now");

        [self hideTabBar:YES];

        [self.navigationController setNavigationBarHidden:YES animated:YES];

    }

    else if ((_lastPosition - currentPostion > 20) && (currentPostion  <= scrollView.contentSize.height-scrollView.bounds.size.height-20) ) //这个地方加上后边那个即可,也不知道为什么,再减20才行

    {

        _lastPosition = currentPostion;

        NSLog(@"ScrollDown now");

       [self hideTabBar:NO];

        [self.navigationController setNavigationBarHidden:NO animated:YES];

    }

    

}






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

自:在我的工程中,我是把  _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 可以是任意数字,可根据自己的需要来设定。


最后,欢迎大家远离我的微博:http://weibo.com/caryaliu


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/780892
推荐阅读
相关标签
  

闽ICP备14008679号