将放大圖檔放在第0行單元格
//建立表視圖
- (void)creatTableView
{
_tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH-64-49) style:UITableViewStylePlain];
[self.view addSubview:_tabView];
_tabView.dataSource = self;
_tabView.delegate =self;
_tabView.backgroundColor = [UIColor clearColor];
_tabView.rowHeight = 80;
}
<pre name="code" class="objc">- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _newsData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ID = @"cell2";
if(indexPath.row != 0) {
NewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell == nil) {
cell = [[NewsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
cell.model = _newsData[indexPath.row];
cell.contentView.backgroundColor = [UIColor blackColor];
return cell;
}
else{
NewsTableViewCell *cell = [[NewsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
}
//scrollView的方法視圖滑動時 實時調用
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// 記錄tabView的偏移量
CGFloat p = scrollView.contentOffset.y;
// 如果y值小于0 說明向下拉
if (p > 0){
_image.top = -p;
// 如果y值大于0 說明向上拉
}else{
CGFloat width = 375*(150+ABS(p))/150.0;
_image.frame = CGRectMake(-(width-375) * 0.5, 0, width, (200+ABS(p)));
_topLable.frame = CGRectMake(-(ScreenW-width)/2.0, _image.height-30, ScreenH, 30);
}
}
//頭部圖檔- (void)creatTopImage{// 頂部圖檔 _image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 200)]; [self.view insertSubview:_image belowSubview:_tabView]; _topLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 200-30, ScreenW, 30)]; _topLable.backgroundColor = [UIColor colorWithWhite:.5 alpha:.5]; _topLable.textColor = [UIColor whiteColor]; _topLable.font = Font14; [_image addSubview:_topLable]; if (_newsData == nil) { return; } NewsModel *model = [_newsData objectAtIndex:0]; //取得圖檔的連接配接 NSString *imgStr = model.image; [_image setImageWithURL:[NSURL URLWithString:imgStr]]; _topLable.text = model.title;}