如何从 UICollectionView 检测滚动方向? [英] How can I detect the scroll direction from the UICollectionView?
本文介绍了如何从 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;
}
这篇关于如何从 UICollectionView 检测滚动方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文