我正在构建一个显示实时滤镜的方形相机。我有一个显示相机预览的 UIView,我在顶部添加了一个 UIImage subview 来覆盖过滤器。我尝试了各种不同的设置,但 UIImageView 总是以错误的宽高比结束。
这是我的
self.imageView = UIImageView(frame: view.bounds)
self.imageView.translatesAutoresizingMaskIntoConstraints = false
self.imageView.contentMode = UIViewContentMode.ScaleToFill
self.imageView.clipsToBounds = true
self.imageView.center = view.center
self.previewLayer!.frame = view.layer.bounds
view.clipsToBounds = true
view.layer.addSublayer(self.previewLayer!)
view.addSubview(self.imageView)
显示相机输出的 UIView 未拉伸(stretch),但我添加为 subview 的 UIView 最终被拉伸(stretch)。未过滤 VS 过滤对比:
最佳答案
请尝试将 contentMode 更改为:
self.imageView.contentMode = UIViewContentMode.ScaleAspectFit
关于ios - UIImageView 实时滤镜在相机预览层上拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37171125/