1.使用代理
<UIScrollViewDelegate>
2.将代理目标设为self(UITableView不需要这一部,因为UITableView本身就继承于UIScrollView)
self.scrollView.delegate = self;
3.
#pragma mark -
#pragma mark - UIScrollView Delegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint offset = scrollView.contentOffset;//scrollview当前显示区域定点相对于fram顶点的偏移量
CGRect bounds = scrollView.bounds;//原点
CGSize size = scrollView.contentSize;//scrollview可以滚动的区域
UIEdgeInsets inset = scrollView.contentInset;//scrollview的contentview的顶点相对于scrollview的位置
CGFloat currentOffset = offset.y + bounds.size.height - inset.bottom;
CGFloat maximumOffset = size.height;
//currentOffset与maximumOffset的值相等时,说明scrollview已经滑到底部了,即偏移量达到最大值
if (offset.y <= 0) {
DLog(@"滑到顶部");
scrollView.contentOffset = CGPointMake(0, 0);
return;
}
if (currentOffset >= maximumOffset) {
DLog(@"滑到底部");
// scrollView.contentOffset = CGPointMake(0, bounds.size.height - offset.y);
// return;
}
}