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)計(jì)算方法
#pragma mark - 改變視圖的狀態(tài)
- (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);
}
}