- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
imageViewHeader = [[UIImageView alloc]init];
imageViewHeader.contentMode = UIViewContentModeScaleAspectFill;//保证图片在放大的过程中高和宽是同时放大的
imageViewHeader.frame = CGRectMake(0, -200, [[UIScreen mainScreen]bounds].size.width,200);
imageViewHeader.clipsToBounds = YES;//需要添加这个不然的话,第一行会有遮盖
imageViewHeader.image = [UIImage imageNamed:@"Image"];
[self.tableViewImageView addSubview:imageViewHeader];
[self.tableViewImageView registerClass:[ImageViewTableViewCell class] forCellReuseIdentifier:@"ImageViewTableViewCell"];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.0001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.001;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ImageViewTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ImageViewTableViewCell" forIndexPath:indexPath];
cell.imageViewIcon.image = [UIImage imageNamed:@"Image-1"];
cell.label.text = [NSString stringWithFormat:@"cell%zd",indexPath.row];
return cell;
}
#pragma mark - 滑动视图的代理方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint point = scrollView.contentOffset;
if (point.y < 0) {
CGRect rect =imageViewHeader.frame;
rect.origin.y = point.y;
rect.size.height = - point.y;
imageViewHeader.frame = rect;
}
}
-(UITableView *)tableViewImageView
{
if (_tableViewImageView == nil) {
_tableViewImageView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width , [[UIScreen mainScreen] bounds].size.height) style:UITableViewStylePlain];
_tableViewImageView.delegate = self;
_tableViewImageView.dataSource = self;
_tableViewImageView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);
[self.view addSubview:_tableViewImageView];
}
return _tableViewImageView;
}
网友评论