美文网首页
tableview下拉放大图片

tableview下拉放大图片

作者: 探路者1202 | 来源:发表于2016-08-30 17:03 被阅读0次

//

//ViewController.m

//下拉方法

//

//Created by lixiang on 16/8/30.

//Copyright © 2016年lixiang. All rights reserved.

//

#import"ViewController.h"

constCGFloattopViewH=350;

@interfaceViewController()

@property(nonatomic,weak)UIImageView* topv;

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

//设置内边距(让cell往下移动一段距离)

self.tableView.contentInset=UIEdgeInsetsMake(topViewH/2,0,0,0);

UIImageView* topImgV=[[UIImageViewalloc]init];

topImgV.image=[UIImageimageNamed:@"test"];

topImgV.frame=CGRectMake(0, -topViewH,self.view.frame.size.width,topViewH);

topImgV.contentMode=UIViewContentModeScaleAspectFill;

[self.tableViewinsertSubview:topImgVatIndex:0];

self.topv=topImgV;

}

#pragma mark -数据源方法

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section

{

return20;

}

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

staticNSString* ID=@"cell";

UITableViewCell* cell=[tableViewdequeueReusableCellWithIdentifier:ID];

if(!cell) {

cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:ID

];

}

cell.textLabel.text=[NSStringstringWithFormat:@"test数据---%ld",indexPath.row];

returncell;

}

-(void)scrollViewDidScroll:(UIScrollView*)scrollView

{

NSLog(@"向下拉了多少=====%f",-topViewH/2-scrollView.contentOffset.y);

//向下拉了多少

CGFloatdown=-150-scrollView.contentOffset.y;

if(down<0) {

return;

}

CGRectframe=self.topv.frame;

frame.size.height=topViewH+down*0.5;//*3(决定图片变大的速度值越大速度越快)

self.topv.frame=frame;

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

相关文章

网友评论

      本文标题:tableview下拉放大图片

      本文链接:https://www.haomeiwen.com/subject/qdtshttx.html