如何从UICollectionView检测滚动方向? [英] How can I detect the scroll direction from the UICollectionView?

查看:237
本文介绍了如何从UICollectionView检测滚动方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UICollectionView.我想检测滚动方向.对于向下滚动和向上滚动,我有两种不同的动画样式.所以我必须学习滚动方向.

I have a UICollectionView. I want to detect scroll direction. I have a two different animation style for scroll down and scroll up. So I must learn scroll direction.

CGPoint scrollVelocity = [self.collectionView.panGestureRecognizer
velocityInView:self.collectionView.superview];

if (scrollVelocity.y > 0.0f)   
NSLog(@"scroll up");

else if(scrollVelocity.y < 0.0f)    
NSLog(@"scroll down");

这只是用手指触摸即可完成的工作.不适合我

This is just work at finger touched. Not work for me

推荐答案

尝试一下:

将此添加到标题中的某个位置:

Add this somewhere in you header:

@property (nonatomic) CGFloat lastContentOffset;

然后覆盖scrollViewDidScroll:方法:

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (self.lastContentOffset > scrollView.contentOffset.y)
    {
        NSLog(@"Scrolling Up");
    }
    else if (self.lastContentOffset < scrollView.contentOffset.y)
    {
        NSLog(@"Scrolling Down");
    }

    self.lastContentOffset = scrollView.contentOffset.y;
}

>找到UIScrollView中滚动的方向了吗?

Found in Finding the direction of scrolling in a UIScrollView?

这篇关于如何从UICollectionView检测滚动方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆