美文网首页
iOS tableview/scrollowview 下拉顶部背

iOS tableview/scrollowview 下拉顶部背

作者: iOS门三闫 | 来源:发表于2020-09-25 10:12 被阅读0次

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);}}

相关文章

网友评论

      本文标题:iOS tableview/scrollowview 下拉顶部背

      本文链接:https://www.haomeiwen.com/subject/tlnxuktx.html