关于UITablView区头跟着滑动的代码:
//定义区头
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 100)];
header.backgroundColor = [UIColor purpleColor];
return header;
}
//滑动的作用部分:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView == self.tableView) {
//区头的高度 根据实际情况修改即可
CGFloat contentHeight = 100;
if (scrollView.contentOffset.y <= contentHeight && scrollView.contentOffset.y > 0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
NSLog(@"当前的scrollView往上滑动: %.2f",scrollView.contentOffset.y);
}else if(scrollView.contentOffset.y >= contentHeight){
scrollView.contentInset = UIEdgeInsetsMake(-contentHeight, 0, 0, 0);
}
}
}