- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 50;
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);
}
}
注意事项
如果设置结束后,滑动出现tableView向上或向下偏移,需要设置controller的属性:
self.automaticallyAdjustsScrollViewInsets = NO;
self.tableView.origin = CGPointMake(0, 64);
self.tableView.height = winHeight-64;