- (void)viewDidLoad{
[super viewDidLoad];
// 创建tableView header view
UIView *headerBackView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, 180)];
_tableView.tableHeaderView = headerBackView;
// 创建imageView
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)];
imageView.image =[UIImage imageNamed:@"imagePic"];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.clipsToBounds = true;
[headerBackView addSubview:imageView];
}
#pragma mark - scrollView delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat width = self.view.frame.size.width; //图片宽度
CGFloat yOffSet = scrollView.contentOffset.y; //偏移量
if (yOffSet < 0) { //表示向下滑动
CGFloat totalOffset = 180 + fabs(yOffSet);
CGFloat f = totalOffset / 180; //缩放系数
imageView.frame = CGRectMake(-(f * width - width)/2, yOffSet, width * f, totalOffset);
}
}
UITableview顶部视图缩放效果
最新推荐文章于 2020-12-30 17:37:47 发布