UITableView設置headerInsectionView不懸浮

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.y00,0);
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 000);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章