iOS tableview/scrollowview 下拉顶部背

2020-09-25  本文已影响0人  iOS门三闫

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

上一篇 下一篇

猜你喜欢

热点阅读