今天做项目时候发现要去掉section在tableview中的黏性
下面代码可以却掉,但是消耗比较大,table滚动时候要不停的执行
//去掉UItableview headerview黏性(sticky)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 40;
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);
}
}下面的方法相对较好
_mainTable.contentInset = UIEdgeInsetsMake(<span style="font-family:Microsoft YaHei;">sectionHeight</span>, 0, 0, 0);这样实际上市吧table向上移动了一部分隐藏在navigation下面
本文介绍如何在iOS开发中解决TableView头部黏性问题,通过优化内容偏移实现更流畅的滚动体验。

315

被折叠的 条评论
为什么被折叠?



