tableView 默認是Plain Style税手,Plain Style 時會出現(xiàn)header吸頂
1. 取消header 懸浮
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// header的高度
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);
}
}
??注意:如果控制多個header都不懸浮锈嫩,sectionHeaderHeight
取最大值試試般妙;
2.修改header懸浮位置
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y >= 0) {
CGFloat top = 100;
scrollView.contentInset = UIEdgeInsetsMake(top, 0, 0, 0);
}
}
??注意:根據(jù)需求修改top
值