美文网首页
设置tableView头部view下拉放大

设置tableView头部view下拉放大

作者: 叶俊谋先生 | 来源:发表于2016-07-28 13:12 被阅读0次

1.先设定头部imageView的原始大小 并且让imageView添加到头部View,这时候头部View最好是tableView的heightView.

UIImageView *HeadImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, _headView.frame.size.width, _headView.frame.size.height)];//此处的高为250

HeadImageView.image = [UIImage imageNamed:@"img_bg"];

[_headView addSubview:HeadImageView];

在scView代理里面实现这行代码即可实现下拉放大

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

CGFloat width = [UIScreen mainScreen].bounds.size.width;

CGFloat yOffset = scrollView.contentOffset.y  ;

//放图片的view有多大  这个的250这两个位置也一样改过来  三个数字一样

if (yOffset < 0) {

CGFloat totalOffset = 250 + ABS(yOffset);

CGFloat f = totalOffset / 250;

_imageView.frame = CGRectMake(- (width * f - width) / 2, yOffset, width * f, totalOffset);

}

}

相关文章

网友评论

      本文标题:设置tableView头部view下拉放大

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