如何检测scrollView滚动方向? [英] How to detect scrollView scrolling direction?
本文介绍了如何检测scrollView滚动方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 UIScrollView
里面有一个 UITableView
滚动视图应该水平滚动。我已经实现了 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
在滚动视图结束其水平滚动时执行某些任务。但我的问题是,即使 UITableView
垂直滚动也停止,此委托也会触发。那么如何在这个代表中只检测 scrollview
水平滚动?
I have a UIScrollView
inside that I have a UITableView
The scroll view should scrol horizontally. And I have implemented - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
to do some tasks when the scroll view end its horizontal scrolling. But My problem is, this delegate is firing even when the UITableView
vertical scrolling stopped too. So how can I detect just the scrollview
horizontal scrolling within this delegate?
请帮助我,
谢谢
Please help me, Thanks
推荐答案
检查这些委托方法
CGPoint _lastContentOffset;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
_lastContentOffset = scrollView.contentOffset;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (_lastContentOffset.x < (int)scrollView.contentOffset.x) {
NSLog(@"Scrolled Right");
}
else if (_lastContentOffset.x > (int)scrollView.contentOffset.x) {
NSLog(@"Scrolled Left");
}
else if (_lastContentOffset.y < scrollView.contentOffset.y) {
NSLog(@"Scrolled Down");
}
else if (_lastContentOffset.y > scrollView.contentOffset.y) {
NSLog(@"Scrolled Up");
}
}
这篇关于如何检测scrollView滚动方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文