#import "ViewController.h"
#define width self.view.bounds.size.width
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
UITableView *_tableView;
UIView *_hearderView;
UIImageView *_imgView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_hearderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width, 200)];
_imgView = [[UIImageView alloc]initWithFrame:_hearderView.frame];
UIImage *img = [UIImage imageNamed:@"1"];
_imgView.image = img;
[_hearderView addSubview:_imgView];
_tableView.tableHeaderView = _hearderView;
[self.view addSubview:_tableView];
}
//指定每组的单元格的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
return cell;
}
//实现下拉放大
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
// 纵向偏移,y轴
CGFloat ysffset = _tableView.contentOffset.y;
// 向上偏移,偏移量为正,向下偏移,偏移量为负
if (ysffset<-64){
// ABS 绝对值
// factor/200 比值,表示偏移后的高度/原始高度
CGFloat factor = ABS(ysffset)+200-64;
CGRect f = CGRectMake(-(width*factor/200-width)/2, -ABS(ysffset)+64, width*factor/200, factor);
_imgView.frame =f;
}else{
// frame不可以直接更改
CGRect f = _hearderView.frame;
f.origin.y =0;
_hearderView.frame = f;
_imgView.frame = CGRectMake(0, f.origin.y, width, 200);
}
}