美文网首页
从的View中获得的图像位置的函数

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

作者: Ink_lhe | 来源:发表于2017-11-27 14:25 被阅读0次
    • (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中获得的图像位置的函数

          本文链接:https://www.haomeiwen.com/subject/zdqdbxtx.html