让 UITableView 的 headerView跟随 cell一起滚动

//The way I solved this problem is to adjust the contentOffset according to the contentInset in the //UITableViewControllerDelegate (extends UIScrollViewDelegate) like this:
 
- (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);
   }
}

 

posted on 2012-12-18 11:02  黯夜曦  阅读(552)  评论(0编辑  收藏  举报

导航