UITableView有兩個headerView:tableHeaderView齿风、和headerInsectionView(組頭視圖)扯罐。
給tableView添加這兩個View:tableHeaderView是通過tableView.tableHeaderView = XXXView 的方式添加的,而headerInsectionView是通過
- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section代理方法添加的败砂。
UITableView的Style為Plain時,當(dāng)tableView上移頂端的tableHeaderView會跟著滑出窗口,而headerInsectionView則會懸浮固定在窗口頂端不隨著滑動繼續(xù)上移抹竹。
UITableView的Style為Grouped時,當(dāng)tableView上移頂端的tableHeaderView會跟著滑出窗口止潮,而headerInsectionView則會隨著滑動繼續(xù)上移窃判。
UITableView的Style為Plain時禁止headerInsectionView固定在頂端:
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
CGFloatsectionHeaderHeight =50;
if(scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset=UIEdgeInsetsMake(-scrollView.contentOffset.y,0,0,0);
}elseif(scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset=UIEdgeInsetsMake(-sectionHeaderHeight,0,0,0);
}
}