#import "TableViewController.h"
@interface TableViewController ()
@property (nonatomic, retain) UIImageView *headerImageView;
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self layoutHeaderImageView];
}
- (void)layoutHeaderImageView {
UIView *headerView = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, self.view.frame.size.width, 200))];
self.headerImageView = [[UIImageView alloc] initWithFrame:(CGRectMake(0, 0, self.view.frame.size.width, 200))];
self.headerImageView.image = [UIImage imageNamed:@"pic5093_sc115.com.jpg"]; // 自己选择的图片
[headerView addSubview:self.headerImageView];
self.tableView.tableHeaderView = headerView;
}
// 下拉后图片拉伸的效果方法下载这个里面
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat width = self.view.frame.size.width; // 图片宽度
CGFloat yOffset = scrollView.contentOffset.y; // 偏移的y值
if (yOffset < 0) {
CGFloat totalOffset = 200 + ABS(yOffset);
CGFloat f = totalOffset / 200;
self.headerImageView.frame = CGRectMake(- (width * f - width) / 2, yOffset, width * f, totalOffset); //拉伸后的图片的frame应该是同比例缩放。
}
}
这个方法是有效的,我自己在刚才又重新写了一遍