1.使用代理代理
<UIScrollViewDelegate>
2.將代理目標設爲self(UITableView不須要這一部,由於UITableView自己就繼承於UIScrollView)code
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; } }