去掉TableView的section header和footer粘性,随着一起滚动

转载自:http://www.cnblogs.com/iCocos/p/4949375.html


只去掉header的

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

if (scrollView == self.tableView)

{

CGFloat sectionHeaderHeight = 64; //你的header高度

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 和 footer 的

UITableView *tableview = (UITableView *)scrollView;

CGFloat sectionHeaderHeight = 64;//头

CGFloat sectionFooterHeight = 120;//脚

CGFloat offsetY = tableview.contentOffset.y;

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

{

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

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

{

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

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

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

}

}

}


如有问题欢迎反馈!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容