- (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中获得的图像位置的函数
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。