美文网首页
ios tableView sectionHeader 吸顶效

ios tableView sectionHeader 吸顶效

作者: 秋S寂S | 来源:发表于2019-11-11 23:40 被阅读0次

ios tableView sectionHeader 吸顶效果

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {// any offset changes
    // change the position of section header when scrolled by changing scroll's contentInset
    CGFloat sectionHeaderHeight = 50;
    CGFloat ceilPositon = CGRectGetHeight(_headerView.frame)-sectionHeaderHeight;
    if (scrollView.contentOffset.y < sectionHeaderHeight){
        scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }
    // the "scrollView.contentOffset.y" must larger than its position to ceiling
    if (scrollView.contentOffset.y>=ceilPositon && scrollView.contentOffset.y>=sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(sectionHeaderHeight, 0, 0, 0);
    } 
}

ceilPositon是我需要的section header的吸顶位置,当tableView的偏移量小于sectionHeaderHeight的时候,正常显示;当tableView的偏移量大于ceilPositon,也就是我们期望的吸顶位置的时候,我们就把scrollView.contentInset的top置为sectionHeaderHeight的高度,于是就实现了我们想要的效果,可以随意更改section header的吸顶位置。同样,此方法也可以使plain类型的tableview失去粘性效果,只需要改变scrollView.contentInset即可.
————————————————

原文链接:https://blog.csdn.net/axllll/article/details/50502475

相关文章

网友评论

      本文标题:ios tableView sectionHeader 吸顶效

      本文链接:https://www.haomeiwen.com/subject/kznxictx.html