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,因为我正在使用通过手机相机拍摄的图像.