#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
static UIView *superV;//scrollView和bannerView的父控件
if (!superV) {
superV = scrollView.superview;
}
if (superV.bounds.origin.y < 0) [superV setBounds:CGRectMake(0, 0, width, height)];//防止向下滑動過快導致的superView向下滑動過多
if (superV.bounds.origin.y > separatH) [superV setBounds:CGRectMake(0, separatH, width, height)];//防止向上滑動過快導致的superView向上滑動過多
if ([scrollView isEqual:self.tableView]) {
CGFloat currentY = superV.bounds.origin.y;
if ((currentY > separatH && scrollView.contentOffset.y > 0) ||//superV已經滑動了banner的高度,並且scrollView是向上滑動,separate是tableView頂部的控件高度
(scrollView.contentOffset.y < 0 && superV.bounds.origin.y <= 0)) return;//superV在初始位置,並且scrollView是向下滑動動作(比如刷新)
[superV setBounds:CGRectMake(0, scrollView.contentOffset.y + currentY, width, height)];//將滑動的距離換位改變superV的可視區域的改變
[self.tableView setContentOffset:CGPointZero];//tableView恢復初始值
}
}
利用bounds處理tableView頂部上下滑動
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.