我内部有一个UIScrollView
我有一个UITableView
滚动视图应该水平滚动。当滚动视图结束其水平滚动时,我已实现- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
来执行某些任务。但我的问题是,即使UITableView
垂直滚动也停止,此委托也会触发。那么如何只检测此委托中的scrollview
水平滚动?
请帮帮我, 感谢
答案 0 :(得分:12)
检查这些委托方法
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");
}
}
答案 1 :(得分:0)
快速版本:
var _lastContentOffset: CGPoint!
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
_lastContentOffset = scrollView.contentOffset
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if _lastContentOffset.x < scrollView.contentOffset.x {
NSLog("Scrolled Right")
}
else if _lastContentOffset.x > 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")
}
}