- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.tableView)
{
CGFloat sectionHeaderHeight = 30; //区头高度
if (scrollView.contentOffset.y <= sectionHeaderHeight&&scrollView.contentOffset.y >=0) {
scrollView.contentInset = UIEdgeInsetsMake(- scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
}
这个方法存在一个弊端,就是当表视图存在导航条的时候,表视图会被导航条遮盖。所以需要添加如下代码
- (void)viewDidAppear:(BOOL)animated
{
self.navigationController.navigationBar.translucent = NO;
}