关于tableView Header的悬浮处理

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

你可能感兴趣的:(关于tableView Header的悬浮处理)