ios UICollectionView检测滚动方向 [英] ios UICollectionView detect scroll direction
本文介绍了ios UICollectionView检测滚动方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个collectionView。我想检测滚动方向。我有两种不同的动画风格,可以向下滚动并向上滚动。所以我必须学习滚动方向。
I have a collectionView. 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;
}
这篇关于ios UICollectionView检测滚动方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文