目标:在LandscapeRight方向上创建AVCaptureVideoPreviewLayer的叠加视图
问题:无法使叠加视图完全适合AVCaptureVideoPreviewLayer。 正在绘制的叠加层的宽度是屏幕宽度的两倍。
这是我想要在相机视图上绘制的叠加视图
这是我在完成以下操作后能够实现的目标。
我的代码
let previewLayer: AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: self.avCaptureSession)
previewLayer.frame = self.view.layer.frame
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
self.view.layer.addSublayer(previewLayer)
let cameraOverlay = CameraOverlay(nibName:"CameraOverlay",bundle: nil)
let cameraOverlayView:CameraOverlayView = cameraOverlay.view as! CameraOverlayView
let previewView = UIView(frame: view.frame)
self.view.addSubview(previewView)
previewView.layer.addSublayer(previewLayer)
self.view.addSubview(cameraOverlayView)
self.avCaptureSession?.startRunning()