覆盖视图通过AVCaptureVideoPreviewLayer

时间:2017-08-07 07:12:22

标签: ios swift camera overlay avcapturesession

目标:在LandscapeRight方向上创建AVCaptureVideoPreviewLayer的叠加视图

问题:无法使叠加视图完全适合AVCaptureVideoPreviewLayer。 正在绘制的叠加层的宽度是屏幕宽度的两倍。

这是我想要在相机视图上绘制的叠加视图

enter image description here

这是我在完成以下操作后能够实现的目标。

enter image description here

我的代码

    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()

0 个答案:

没有答案