sectionHeaderView ,sectionfooter

作者: M_PI_4 | 来源:发表于2019-02-27 16:59 被阅读0次
演示.gif
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    //sectionHeader不悬浮
//    if (scrollView == self.tabView)
//    {
//        CGFloat sectionHeaderH = sectionHeaderHeight;  //sectionHeaderHeight
//        CGFloat sectionFooterH = sectionFooterHeight;
//
//        UITableView *tableview = (UITableView *)scrollView;
//
//        if (scrollView.contentOffset.y<=sectionHeaderH&&scrollView.contentOffset.y>=0) {
//            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
//        } else if (scrollView.contentOffset.y>=sectionHeaderH) {
//            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderH, 0, 0, 0);
//        }
//    }
    
    //sectionHeader以及sectionFooter不悬浮
    if (scrollView == self.tabView)
    {
        UITableView *tableview = (UITableView *)scrollView;
        CGFloat sectionHeaderH = sectionHeaderHeight;
        CGFloat sectionFooterH = sectionFooterHeight;
        CGFloat offsetY = tableview.contentOffset.y;
        if (offsetY >= 0 && offsetY <= sectionHeaderH)
        {
            tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterH, 0);
            
        }else if (offsetY >= sectionHeaderH && offsetY <= tableview.contentSize.height - tableview.frame.size.height - sectionFooterH)
        {
            tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderH, 0, -sectionFooterH, 0);
        }else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterH && offsetY <= tableview.contentSize.height - tableview.frame.size.height)
        {
            tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(tableview.contentSize.height - tableview.frame.size.height - sectionFooterH), 0);
        }
    }
}

相关文章

网友评论

    本文标题:sectionHeaderView ,sectionfooter

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