ps:copy同伴的代码的,不知道他从哪里copy的,在这里仅做记录
1.效果图
2.啥也不说了,上代码
1) scrollview的代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
#if 1
CGFloat offsetY = scrollView.contentOffset.y;
if (offsetY < - 1) {
if (offsetY > - 200) {
//修改本地
[self.headerView imageViewStretchingWithOffSet:offsetY];
}
}
#endif
}
2)计算方法
#pragma mark - 改变视图的状态
- (void)imageViewStretchingWithOffSet:(CGFloat)offset {
// NSLog(@"%f---%f",offset,self.headImageView.frame.size.width);
CGFloat whPercent = self.orginWidth / self.orginHeight;//原始比例
CGFloat height = self.orginHeight - offset;//拉伸后的高度
CGFloat width = self.orginWidth - offset * whPercent;//拉伸后的宽度
CGFloat newHeadWidth = self.headWidth - offset;
CGFloat newHeadOriginY = self.headOriginY + offset;
if (offset < -1.5) {
self.bgImageView.frame = CGRectMake(offset / 3 * 2, offset, width, height);
if (newHeadWidth > kUserInfoHeadViewWidth - (self.headOriginX * 4)) {
//超过不做处理
}else{
self.headImageView.frame = CGRectMake(self.headOriginX, newHeadOriginY, newHeadWidth, newHeadWidth);
}
}else {
self.bgImageView.frame = CGRectMake(0, 0, self.orginWidth, self.orginHeight);
self.headImageView.frame = CGRectMake(self.headOriginX, self.headOriginY, self.headWidth, self.headHeight);
}
}