1 先把imageview添加在tableview上,注意大小位置,-150
_heroBigImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hero_bg.jpg"]];
_heroBigImageView.frame = CGRectMake(0, -150, 320, 150);
[_tableView addSubview:_heroBigImageView];
2 設置tableview的contentInset,向下移動150
_tableView.contentInset = UIEdgeInsetsMake(150, 0, 0, 0);
3 scrollview的代理,獲取contentoffset,然后從新設置imageview的frame
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//獲取當前活動的tableview
CGFloat y = scrollView.contentOffset.y;
if (scrollView == _tableView) {
if (y < -150) {
CGRect frame = _heroBigImageView.frame;
frame.size.height = - y ;
frame.origin.y = y;
_heroBigImageView.frame = frame;
}
}
}