1.@property(nonatomic,strong)UIView*headerBgView;
2.-(UIView*)headerBgView{
if(!_headerBgView){
_headerBgView = [UIView new];
_headerBgView.backgroundColor=[UIColor redColor];
}
return _headerBgView;
}
3.[self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil];
[self.tableView.superview addSubview:self.headerBgView];
4.-(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id>*)change context:(void*)context{
if([keyPath isEqualToString:@"contentOffset"]){
NSValue *value = change[NSKeyValueChangeNewKey];
CGFloat chaneoffsetY = value.UIOffsetValue.vertical;
self.headerBgView = CGRectMake(0,0,SCREEN_WIDTH,-chaneoffsetY);}}
网友评论