UIView *headerView = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, self.view.frame.size.width, 200))];spa
self.headerImageView = [[UIImageView alloc] initWithFrame:(CGRectMake(0, 0, self.view.frame.size.width, 200))];3d
self.headerImageView.backgroundColor = CHEX(0x3db0fe); // 本身選擇的圖片代理
[headerView addSubview:self.headerImageView];blog
self.tableView.tableHeaderView = headerView;圖片
self.tableView.contentInset = UIEdgeInsetsMake(-200, 0, 0, 0);it
self.tableView.delegate = self;io
self.tableView.dataSource = self;table
[self.tableView registerClass:[HBMyOrderCell class] forCellReuseIdentifier:@"HBMyOrderCellID"];class
[self.tableView registerClass:[HBActionCell class] forCellReuseIdentifier:@"HBActionCellID"];scroll
[self.tableView registerClass:[HBOtherActionCell class] forCellReuseIdentifier:@"HBOtherActionCelllID"];
[self.view addSubview:self.tableView];
代理方法:
- (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應該是同比例縮放。
}
}