我在 UIView 上添加了一个 Imageview,并设置了属性 AspectToFit。根据应用要求,我需要在 imageview 上再添加一张图片。
float width;
float height;
float x;
float y;
CGSize imageViewSize = self.getImageView.bounds.size;// self.getImageView.frame.size;
CGSize imageSize = self.getImage.size;
CGFloat minFactor = imageViewSize.width / imageSize.width;
if (imageViewSize.height / imageSize.height < minFactor)
{
minFactor = imageViewSize.height / imageSize.height;
}
CGRect frame = self.getImageView.frame;
NSLog(@"view height..%@",NSStringFromCGRect (frame));
CGSize resultSize = CGSizeMake(minFactor * imageSize.width, minFactor * imageSize.height);
UIImage *newimage = [self imageWithImage:self.getImage scaledToSize:resultSize];
float mainwidth = imageViewSize.width;
float mainheight = imageViewSize.height;
float imagewidth = newimage.size.width;
float imageheight = newimage.size.height;
_widthdiff = mainwidth-imagewidth;
_heightdiff = mainheight-imageheight;
x = self.view.frame.size.width-width-0-_widthdiff/2;
y = self.view.frame.size.height-height-116-_heightdiff/2;
imageview = [[UIImageView alloc]
initWithFrame:CGRectMake(x, y, width, height)];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
此代码适用于除 iPhone(iPhone 6 Plus、iPone 7 Plus)以外的所有设备。正如我所见,仅在 Plus 尺寸的设备中存在问题。
计算imageview和正确图像之间的差异或比率是否有不同?请指教。