32. 如何优雅地获取 ScrollView 的滚动方向
// @property (nonatomic, assign) CGFloat lastContentOffset;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (self.lastContentOffset > scrollView.contentOffset.y) {
// 向下滚动
} else if (self.lastContentOffset < scrollView.contentOffset.y) {
// 向上滚动
}
self.lastContentOffset = scrollView.contentOffset.y;
}- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint point = [scrollView.panGestureRecognizer translationInView:self.view];
if (point.y > 0) {
// 向下滚动
} else {
// 向上滚动
}
}
参考连接
Last updated
Was this helpful?