![实现UITableView <wbr>Plain <wbr>SectionView和table不停留一起滑动 实现UITableView <wbr>Plain <wbr>SectionView和table不停留一起滑动](https://img-blog.csdnimg.cn/img_convert/c977c62d883f22ba11dfe552cae32018.gif)
1) 这个代码是通过scroll偏移量来监听和改变你的tableview的contentInset 可见很不好(试试就知道)
X
// 去掉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);
}
}
2)和第一个没太大本质区别,在自定义headSectionView中重写setframe方法来重载table的section
- (void)setFrame:(CGRect)frame{
CGRect sectionRect = [self.tableView rectForSection:self.section];
CGRect newFrame = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(sectionRect), CGRectGetWidth(frame), CGRectGetHeight(frame)); [super setFrame:newFrame];
}
总结:
网上很多问题在问如何解决随tableview一起滑动,想group样式一样实现粘性的问题。这个setframe重载section很使用,在footview也一样。
这里有TablePlainSectionDemo 可以直接下载看下。希望能帮你解决类似次问题。
一起扯扯,码农blog建设中 欢迎访问。