剛開始在繼承
UITableViewHeaderFooterView
的自定義sectionHeader內部,設置self.backgroundColor = [UIColor whiteColor];
結果依舊顯示灰色bash而後開始在代理方法
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
裏,設置footer.backgroundColor
,依舊失敗spa
在代理方法- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
裏設置backgroundView
:代理
footer.backgroundView = [[UIImageView alloc] initWithImage:[UIImage ehs_imageWithColor:kBackgroundColor_Gray size:CGSizeMake(SCREEN_WIDTH, kSectionFooterHeight)]];
複製代碼
網上一搜,會出現不少,大體都是在scroll的代理方法裏設置tableview.contentInset
code
- (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);
}
}
複製代碼
UITableview處理section的不懸浮,禁止section停留的方法,主要是這段代碼
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.tableView)
{
UITableView *tableview = (UITableView *)scrollView;
CGFloat sectionHeaderHeight = kSectionHeaderHeight;
CGFloat sectionFooterHeight = kSectionFooterHeight;
CGFloat offsetY = tableview.contentOffset.y;
HMLog(@"offsetY---%f",offsetY);
if (offsetY >= 0 && offsetY <= sectionHeaderHeight)
{
tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);
}else if (offsetY >= sectionHeaderHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight)
{
tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);
}else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height)
{
tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight), 0);
}
}
}
複製代碼
但其實仍是沒有用,依舊會有bug,親測的方法是改變table的style繼承
UITableViewStyleGrouped
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - Height_NavBar - kTopTailViewHeight)];
string
|| 改成:it
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - Height_NavBar - kTopTailViewHeight) style:UITableViewStyleGrouped];
io