关于tableView Header的悬浮处理

2017-12-29  本文已影响0人  娜娜的世界123

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

上一篇 下一篇

猜你喜欢

热点阅读