关于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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容