UITableView有兩個headerView:tableHeaderView、和headerInsectionView(組頭視圖)。
給tableView添加這兩個View:
tableHeaderView是通過tableView.tableHeaderView = XXXView 的方式添加的,而headerInsectionView是通過
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section代理方法添加的。
UITableView的Style爲Plain時,當tableView上移頂端的tableHeaderView會跟着滑出窗口,而headerInsectionView則會懸浮固定在窗口頂端不隨着滑動繼續上移。
UITableView的Style爲Grouped時,當tableView上移頂端的tableHeaderView會跟着滑出窗口,而headerInsectionView則會隨着滑動繼續上移。
UITableView的Style爲Plain時禁止headerInsectionView固定在頂端:- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionHeaderHeight = 50;
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);
}
}