tableView 默认是Plain Style,Plain Style 时会出现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);
}
}
⚠️注意:根据需求修改top
值