美文网首页
设置ios tableView的section Header &

设置ios tableView的section Header &

作者: c5550ea746f8 | 来源:发表于2017-12-07 15:22 被阅读183次

    //设置tableView的Sectionheader不吸附

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    CGFloat sectionHeaderHeight = SectionHeight;

    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);

    }

    }

    //设置tableView的SectionFooter不吸附

    - (void)scrollViewDidScroll:(UIScrollView*)scrollView {

    CGFloatsectionFooterHeight =40;

    CGFloatButtomHeight = scrollView.contentSize.height -self.tableView.frame.size.height;

        if    (ButtomHeight-sectionFooterHeight <= scrollView.contentOffset.y && scrollView.contentSize.height >0) {

             scrollView.contentInset =UIEdgeInsetsMake(0,0,0,0);

        }else

        { 

         scrollView.contentInset =UIEdgeInsetsMake(0,0, -(sectionFooterHeight),0);

        }

    }

    //设置tableView的SectionHeader & SectionFooter不吸附

    CGFloat sectionHeaderHeight = 44;//头

    CGFloat sectionFooterHeight = 64;//脚

    CGFloat offsetY = scrollView.contentOffset.y;

    if (offsetY >= 0 && offsetY <= sectionHeaderHeight)

    {

         scrollView.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);

       }else if (offsetY >= sectionHeaderHeight && offsetY <= scrollView.contentSize.height - scrollView.frame.size.height - sectionFooterHeight)

    {

    scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);

    }else if (offsetY >= scrollView.contentSize.height - scrollView.frame.size.height - sectionFooterHeight && offsetY <= scrollView.contentSize.height - scrollView.frame.size.height)

    {

    scrollView.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(scrollView.contentSize.height - scrollView.frame.size.height - sectionFooterHeight), 0);

    }

    相关文章

      网友评论

          本文标题:设置ios tableView的section Header &

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