iOS开发-设置headerInsectionView不悬浮

来源:互联网 发布:视频监控软件免费版 编辑:程序博客网 时间:2024/04/29 02:58
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);

    }

}

原创粉丝点击