主要原理是根据,UITableView 的 contentOffset 的偏移量计算头部 tableHeaderView 中的 UIImageView 的高度,并实时改变


// iOS 9 之前的API - (void)willMoveToSuperview:(UIView *)newSuperview
- (void)willMoveToSuperview:(nullable UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
    _scrollView = (UIScrollView *)newSuperview;
    _imgView.frame = CGRectMake(0, 0, newSuperview.bounds.size.width, self.frame.size.height);
    [_scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
    [_scrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
    
}

// iOS 9 之前的API - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
    
    if (object == _scrollView) {
        NSLog(@"TableHeadScaleView %f", _scrollView.contentOffset.y);
        
        if ([keyPath isEqualToString:@"contentOffset"]) {
            if (_scrollView.contentOffset.y < 0) {
                _imgView.frame = CGRectMake(0, _scrollView.contentOffset.y, _imgView.bounds.size.width, 90+ABS(_scrollView.contentOffset.y));
            }
            
        }else if ([keyPath isEqualToString:@"contentInset"]) {
            
        }
    }
    
}