ios_scrollView顶部图片下拉放大

- (UIScrollView *)bgScrollView{
    if(!bgScrollView){
        bgScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.statusView.frame), CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-20-49)];
        bgScrollView.delegate=self;
        bgScrollView.showsVerticalScrollIndicator=NO;
        bgScrollView.showsHorizontalScrollIndicator=NO;
        bgScrollView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#f6f6f6"];
        bgScrollView.hidden=YES;
        bgScrollView.contentInset = UIEdgeInsetsMake(142*CGRectGetWidth(self.view.frame)/375, 0, 0, 0);
    }
    return bgScrollView;
}

- (UIImageView *)topImageView{
    if(!topImageView){
        topImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,-(142*CGRectGetWidth(self.view.frame)/375), CGRectGetWidth(self.view.frame),142*CGRectGetWidth(self.view.frame)/375)];
        topImageView.backgroundColor = [UIColor hx_colorWithHexRGBAString:@"#ffffff"];
        topImageView.contentMode = UIViewContentModeScaleAspectFill;
        [topImageView sd_setImageWithURL:[NSURL URLWithString:@"www.baidu.com"] placeholderImage:[UIImage imageNamed:@"top_logo.png"] options:SDWebImageRetryFailed];
    }
    return topImageView;
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGPoint point = scrollView.contentOffset;
    if (point.y < -(142*CGRectGetWidth(self.view.frame)/375)) {
        CGRect rect = self.topImageView.frame;
        rect.origin.y = point.y;
        rect.size.height = -point.y;
        self.topImageView.frame = rect;
    }
}

1.设置scrollview图片偏移

2.设置图片frame

3.在滑动代理中修改图片frame

原文地址:https://www.cnblogs.com/YuFly-lyx/p/8066475.html