[self.tableView reloadData];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.tableView insertSubview:self.header_backgroundView atIndex:0];
});
首先,在tableView刷新之后,调用 [self.tableView insertSubview:self.header_backgroundView atIndex:0]; 方法,
效果如图
然后,监听tableView的滚动事件,在滚动的过程中将子视图在插入到最底层,
[scrollView vv_addObserver:scrollViewHelper forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew withBlock:^(NSDictionary * _Nonnull change, void * _Nonnull context) {
[scrollViewHelper scrollViewDidSroll:weakScrollView superViewInsetHeight:offset];
[weakScrollView insertSubview:headerConfig.backgroundView atIndex:0];
}];
这里和collectionView有点不同,需要在tableveiw滚动的过程中不停的调动改方法,不然的话会导致cell 被覆盖
如果在监听或者滚动的代理方法中不插入到底层,滚动过之后效果如图