如何在现有UIView中将videoPreviewLayer居中??我已经尝试了以下方法,但它比我想要的要小。
var videoPreviewLayer : AVCaptureVideoPreviewLayer?
let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)
do {
let input = try AVCaptureDeviceInput(device: captureDevice!)
captureSession = AVCaptureSession()
captureSession?.addInput(input)
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
// let frame : CGRect = self.scanView.layer.bounds
// videoPreviewLayer?.frame = frame
videoPreviewLayer?.frame = self.scanView.bounds
// videoPreviewLayer?.bounds = self.view.bounds
scanView.layer.addSublayer(videoPreviewLayer!)
captureSession?.startRunning()
} catch {
print("error-jz")
}
capturePhotoOutput = AVCapturePhotoOutput()
capturePhotoOutput?.isHighResolutionCaptureEnabled = true
captureSession?.addOutput(capturePhotoOutput!)```发布于 2020-05-11 09:38:15
它应该在您添加videoPreviewLayer到的任何视图中居中。然而,当你说它比你想要的要小的时候,这可能是因为你没有为播放器层设置视频重力。
videoPreviewLayer.videoGravity = .resizeAspectFill这将使视频预览填充它所包含的整个视图。如果它仍然没有按你想要的方式居中,你可能不得不修复UIView本身的居中问题。
https://stackoverflow.com/questions/61716279
复制相似问题