设置ios tableView的section Header & Footer跟着tableView一起滚动

//设置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 & Footer跟着tableView一起滚动)