ios的tableview中headerview会随着滑动黏在上方,直到新的sectionheaderview出现并替换掉,这是个好的特性,但是在为了实现PM某些需求的时候,又不是很符合心意,在网上查了下,找到了其解决方法:
- // 去掉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);
- }
- }
利用控制scrollView的滑动来控制headView显示与否。