ios UITableView头部带有图片并且下拉图片放大效果

2017-07-27  本文已影响0人  尹时允

一.位置确定

img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];

img.image = [UIImage imageNamed:@"headerImage1.jpg"];

UIView *v1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];

table.tableHeaderView = v1;

[v1 addSubview:img];

UIView *v2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

table.backgroundView = v2;

[v2 addSubview:img];

二.实现滑动效果

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGRect tempRect = img.frame;

if (scrollView.contentOffset.y > 0) {

tempRect.origin.y = -scrollView.contentOffset.y;

img.frame = tempRect;

}else {

tempRect.origin.y = 0;

tempRect.size.height = 200 - scrollView.contentOffset.y;

img.frame = tempRect;

}

上一篇下一篇

猜你喜欢

热点阅读