简体   繁体   中英

UIImageView live filter being stretched over camera preview layer

I am building a square camera that displays live filters. I have a UIView which displays the camera preview and I am adding a UIImage subview on top to overlay the filter. I have tried a variety of different settings but the UIImageView always ends up being the wrong aspect ratio.

Here is what I have

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)

The UIView displaying the camera output is not stretched but the UIView I add as a subview ends up being stretched. A comparison of unfiltered VS filtered:

未过滤:

已过滤:

请尝试将contentMode更改为此:

self.imageView.contentMode = UIViewContentMode.ScaleAspectFit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM