- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.tableView)
{
CGFloat sectionHeaderHeight = 30; //區(qū)頭高度
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);
}
}
}
這個(gè)方法存在一個(gè)弊端,就是當(dāng)表視圖存在導(dǎo)航條的時(shí)候,表視圖會(huì)被導(dǎo)航條遮蓋。所以需要添加如下代碼
- (void)viewDidAppear:(BOOL)animated
{
self.navigationController.navigationBar.translucent = NO;
}