TableView头部图片下拉图片放大
2016-09-06 18:10
381 查看
浏览商品时,组头放置的商品图片,下拉UITableView,会有头部图片放大的效果
1.宏定义
#define WIDTH [[UIScreen mainScreen] bounds].size.width
#define HEIGHT [[UIScreen mainScreen] bounds].size.height
#define NavigationBarHeight 64
#define ImageHeight 250
2.遵循协议、定义属性
@interface
ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView
*tableView;
//底层背景图
@property(nonatomic,strong)UIImageView
*zoomImageView;
//图像
@property(nonatomic,strong)UIImageView
*circleView;
//昵称
@property(nonatomic,strong)UILabel
*label;
3.上代码
//1.初始化_tableView
self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
//2.设置代理
self.tableView.dataSource=self;
self.tableView.delegate=self;
//3.设置contentInset属性(上左下右的值)
self.tableView.contentInset = UIEdgeInsetsMake(ImageHight+64,0,0,0);
//4.添加tableView
[self.view addSubview:self.tableView];
//5.配置ImageView
self.zoomImageView=[[UIImageView alloc]initWithImage:[UIImageimageNamed:@"123.jpg"]];
self.zoomImageView.frame = CGRectMake(0,
-ImageHight ,self.view.frame.size.width,ImageHight);
//核心代码
//UIViewContentModeScaleAspectFill高度改变,宽度也会改变
//不设置那将只会被纵向拉伸
self.zoomImageView.contentMode
= UIViewContentModeScaleAspectFill;
[self.tableView addSubview:self.zoomImageView];
4. 相关协议方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//根据实际选择加不加上NavigationBarHeigth
CGFloat y = scrollView.contentOffset.y;
if(y < -ImageHight){
CGRect frame=self.zoomImageView.frame;
frame.origin.y=y;
frame.size.height=-y;
self.zoomImageView.frame=frame;
}
}
#pragma mark - TableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"SharkTop"];
if(cell==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"SharkTop"];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
cell.separatorInset=UIEdgeInsetsZero;
cell.clipsToBounds =YES;
}
cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
return cell;
}
1.宏定义
#define WIDTH [[UIScreen mainScreen] bounds].size.width
#define HEIGHT [[UIScreen mainScreen] bounds].size.height
#define NavigationBarHeight 64
#define ImageHeight 250
2.遵循协议、定义属性
@interface
ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView
*tableView;
//底层背景图
@property(nonatomic,strong)UIImageView
*zoomImageView;
//图像
@property(nonatomic,strong)UIImageView
*circleView;
//昵称
@property(nonatomic,strong)UILabel
*label;
3.上代码
//1.初始化_tableView
self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
//2.设置代理
self.tableView.dataSource=self;
self.tableView.delegate=self;
//3.设置contentInset属性(上左下右的值)
self.tableView.contentInset = UIEdgeInsetsMake(ImageHight+64,0,0,0);
//4.添加tableView
[self.view addSubview:self.tableView];
//5.配置ImageView
self.zoomImageView=[[UIImageView alloc]initWithImage:[UIImageimageNamed:@"123.jpg"]];
self.zoomImageView.frame = CGRectMake(0,
-ImageHight ,self.view.frame.size.width,ImageHight);
//核心代码
//UIViewContentModeScaleAspectFill高度改变,宽度也会改变
//不设置那将只会被纵向拉伸
self.zoomImageView.contentMode
= UIViewContentModeScaleAspectFill;
[self.tableView addSubview:self.zoomImageView];
4. 相关协议方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//根据实际选择加不加上NavigationBarHeigth
CGFloat y = scrollView.contentOffset.y;
if(y < -ImageHight){
CGRect frame=self.zoomImageView.frame;
frame.origin.y=y;
frame.size.height=-y;
self.zoomImageView.frame=frame;
}
}
#pragma mark - TableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"SharkTop"];
if(cell==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"SharkTop"];
cell.selectionStyle =UITableViewCellSelectionStyleNone;
cell.separatorInset=UIEdgeInsetsZero;
cell.clipsToBounds =YES;
}
cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
return cell;
}
相关文章推荐
- 类似于手机qq空间的下拉tableView上面的图片放大的功能的实现
- tableView下拉图片放大
- 下拉tableView上面的图片放大
- tableView下拉放大头部视图
- tableview下拉的时候,头部图片放大效果view下拉的时候,头部图片放大效果
- tableView图片下拉放大
- [IOS]对UITableView的简单封装,实现了下拉放大头部图片的效果
- iOS下拉tableView实现上面的图片放大效果
- 下拉 放大tableview上方 图片
- 猫猫学iOS之tableView的下拉放大图片的方法
- ios tableview下拉头部图片变大
- AJ学IOS 之tableView的下拉放大图片的方法
- tableview 下拉图片放大
- swift 下拉放大tableView顶部图片 或 放大顶部地图
- iOS tableView实现下拉图片放大效果
- iOSUITableView头部带有图片并且下拉图片放大效果
- UITableView头部带有图片并且下拉图片放大效果
- [iOS]实现UITableView头部带有图片并且下拉图片放大效果
- iOS:tableView表头下拉放大的效果
- iOS开发-UITableView顶部图片下拉放大