ios的tableview中headerview会随着滑动黏在上方,直到新的sectionheaderview出现并替换掉,这是个好的特性,但是在为了实现PM某些需求的时候,又不是很符合心意,在网上查了下,找到了其解决方法:

  1. // 去掉UItableview headerview黏性(sticky)
  2. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  3. {
  4.     CGFloat sectionHeaderHeight = 40;
  5.     if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
  6.         scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
  7.     }
  8.     else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
  9.         scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
  10.     }
  11. }

利用控制scrollView的滑动来控制headView显示与否。