ios - UIImageView 实时滤镜在相机预览层上拉伸(stretch)

标签 ios swift camera uiimageview

我正在构建一个显示实时滤镜的方形相机。我有一个显示相机预览的 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 过滤对比:

Unfiltered:

Filtered:

最佳答案

请尝试将 contentMode 更改为:

self.imageView.contentMode = UIViewContentMode.ScaleAspectFit

关于ios - UIImageView 实时滤镜在相机预览层上拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37171125/

相关文章:

ios - 如何在 XCode 中重置 GPS 首选项?

ios - 在 SpriteKit 中更改 contactTestBitMask 后检测接触

iphone - 如何实时修改来自 iPhone 摄像头的视频流?

ios - UITableViewCell 子类中的 UIButton 未注册水龙头

ios - 如何修复错误 : 'The app identifier "com. example.apple-samplecode.BreakfastFinder“无法注册到您的开发团队。”

ios - 将 willSet block 分配给 iOS isResting 属性

Swift:你如何理解这个函数签名: func curry<A, B, C>(f: (A, B) -> C) -> A -> B -> C

iphone - 将闪光灯模式设置为默认关闭

java - 通过 Intent 使用手机摄像头 - Activity 永远不会返回?

iOS 核心数据 : Refetch of subcategories necessary?