【发布时间】:2016-03-08 19:36:48
【问题描述】:
我正在使用 AVFoundation 进行一些视频录制,并且我已经查看了如何让视频进行方面填充。我已经阅读了苹果的 avfoundation 指南和 AVCaptureVideoPreviewLayer 的类参考。我也在这里阅读了这个问题AVFoundation camera preview layer not working。这是我的代码
videoPreviewLayer.frame = captureView.frame
videoPreviewLayer.frame.origin = CGPoint(x: 0, y: 0)
videoPreviewLayer.backgroundColor = UIColor.redColor().CGColor
videoPreviewLayer.contentsGravity = AVLayerVideoGravityResizeAspectFill
videoPreviewLayer.masksToBounds = true
captureView.layer.addSublayer(videoPreviewLayer)
我把它放在viewDidLayoutSubviews() 中,这样我就可以获得 captureView.frame 的正确大小,这是我的 previewLayer 所在的 UIView。任何线索为什么 aspectFill 不起作用?正如您从红色背景中看到的,图层大小正确,但 contentsGravity 没有填充图层。
【问题讨论】:
标签: ios swift avfoundation