- (CGRect)getFrameSizeForImage:(UIImage *)image inImageView:(UIView *)backView {
float hfactor = image.size.width / backView.frame.size.width;
float vfactor = image.size.height / backView.frame.size.height;
float factor = fmax(hfactor, vfactor);
//将尺寸除以垂直或水平收缩因子中较大的一个
float newWidth = image.size.width / factor;
float newHeight = image.size.height / factor;
//然后确定是否需要将其偏移到垂直或水平居中
float leftOffset = (backView.frame.size.width - newWidth) / 2;
float topOffset = (backView.frame.size.height - newHeight) / 2;
return CGRectMake(leftOffset, topOffset, newWidth, newHeight);
}
网友评论