ios – Swift UIImageView拉伸方面

UI ImageView不正确地渲染图像的大小.使用Scale Aspect Fit,如果UIImageView是一个正方形,图像是正确的宽高比,透明度在图像不填充的区域.
//Image is Square & Correct Size
var imageView = UIImageView(frame: CGRectMake(0,50,320,320))
imageView.clipsToBounds = true
imageView.contentMode = UIViewContentMode.ScaleAspectFit

//Image is Rectangle & Incorrect Size
var imageView = UIImageView(frame: CGRectMake(0,450))
imageView.clipsToBounds = true
imageView.contentMode = UIViewContentMode.ScaleAspectFit

UIImageView需要触摸边缘,并且在屏幕的顶部和底部具有透明空间,并且内部的图像需要保持其原始比例而不是拉伸更高.我附上了UIImageView中图像呈现的两个图像.

解决方法

我向UIImageView添加一个自动调整蒙版,现在显示正确的比例.
imageView.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibletopMargin | UIViewAutoresizing.FlexibleWidth
imageView.contentMode = UIViewContentMode.ScaleAspectFit

这个答案帮助我:Captured photo is stretched with AVCaptureSession sessionPreset = AVCaptureSessionPresetPhoto,因为我正在使用通过手机相机拍摄的图像.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...