-(void)scrollViewDidScroll:(UIScrollView *)scrollView  
{  
    if (scrollView.tag == 100102) {  
        UITableView *tableview = (UITableView *)scrollView;  
        CGFloat sectionHeaderHeight = 20;  
        CGFloat sectionFooterHeight = 20;  
        CGFloat offsetY = tableview.contentOffset.y;  
        if (offsetY >= 0 && offsetY <= sectionHeaderHeight)  
        {  
            tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);  
        }else if (offsetY >= sectionHeaderHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight)  
        {  
            tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);  
        }else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height)  
        {  
            tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight), 0);  
        }  
    }  
}  

缺点:

这个方法目前只适用于headerView和footerView的高度都是固定值的情况,另外在滚动到最后一个footerView即将显示的时候,滚动条变化有点儿突然

本文地址: http://yongqianvip.github.io/2015/02/15/tableViewHeaderFooterView/