满足了tableheaderview的自定义显示和隐藏。这里只是提供一种思路给大家,有更好的方法记得和我分享[坏笑]。view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
view.backgroundColor=[UIColor redColor];
_tableView.tableHeaderView=nil;
[_tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:Nil];
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
NSLog(@"change=%@",change);
static int b=0;
if (_tableView.contentOffset.y<=-20 && b%2==0) {
_tableView.tableHeaderView=view;
}else if (_tableView.contentOffset.y>=20 && b%2==1){
_tableView.tableHeaderView=nil;
}
b++;
}
隐藏和显示tableview.tableheaderview
最新推荐文章于 2023-10-17 17:05:35 发布
直接 上代码