从的View中获得的图像位置的函数

  • (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);
    }

你可能感兴趣的:(从的View中获得的图像位置的函数)