以collectionView为例
<UIScrollViewDelegate >
@property (nonatomic, assign) NSInteger lastcontentOffset;
self.collectionView.delegate = self;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat hight = scrollView.frame.size.height;
CGFloat contentOffset = scrollView.contentOffset.y;
CGFloat distanceFromBottom = scrollView.contentSize.height - contentOffset;
CGFloat offset = contentOffset - self.lastcontentOffset;
self.lastcontentOffset = contentOffset;
if (offset > 0 && contentOffset > 0) {
NSLog(@"上拉行为");
}
if (offset < 0 && distanceFromBottom > hight) {
NSLog(@"下拉行为");
}
if (contentOffset == 0) {
NSLog(@"滑动到顶部");
}
if (distanceFromBottom < hight) {
NSLog(@"滑动到底部");
}
}