下拉头像放大

- (void)viewDidLoad {

[super viewDidLoad];

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

self.automaticallyAdjustsScrollViewInsets = NO;

_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, navH, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) - navH) style:UITableViewStylePlain];

_tableView.delegate = self;

_tableView.dataSource = self;

/* 设置tableView的偏移量 **/

_tableView.contentInset = UIEdgeInsetsMake(startImageViewH, 0, 0, 0);

[self.view addSubview:_tableView];

/*

* 注意 imageView 的Y 值是-startImageViewH 其实这个值就是 tableView的内容偏移量

* 如果Y 是0的话它还是会跟着tableView偏移startImageViewH 值

**/

UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -startImageViewH, CGRectGetWidth(self.view.frame), startImageViewH)];

imageView.image = [UIImage imageNamed:@"1"];

self.imageView = imageView;

[self.tableView addSubview:imageView];

}

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

CGFloat offsetY = scrollView.contentOffset.y;

NSLog(@"offsetY = %f",offsetY);

/* 计算往下拉的时候偏移量 **/

if (offsetY < -startImageViewH) {

/* 计算差值 **/

CGFloat interval = -CGRectGetHeight(self.imageView.frame) - offsetY;

/* imageView 的高度 增加 interval **/

CGFloat imageViewH = CGRectGetHeight(self.imageView.frame) + interval;

/* 计算 imageView的 高度增加后的,宽度增加后的值  **/

CGFloat imageViewW = imageViewH*CGRectGetWidth(self.imageView.frame)/CGRectGetHeight(self.imageView.frame);

/* 计算 imageView X 的偏移量 **/

CGFloat imageViewX =self.imageView.frame.origin.x - (imageViewW -CGRectGetWidth(self.imageView.frame))/2;

/* 计算 imageView Y 的偏移量 **/

CGFloat imageViewY =self.imageView.frame.origin.y - interval;

/* 赋值 **/

self.imageView.frame = CGRectMake(imageViewX, imageViewY, imageViewW, imageViewH);

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容