AVCaptureVideoPreviewLayer swift 4的句柄方向更改

时间:2019-01-24 00:16:53

标签: swift

我正在尝试解决AVCaptureVideoPreviewLayer的方向变化,但是没有运气

 let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
    previewLayer.frame = view.bounds
    previewLayer.videoGravity = AVLayerVideoGravity.resizeAspect

    var previewLayerConnection: AVCaptureConnection? = previewLayer.connection

    if previewLayerConnection?.isVideoOrientationSupported != nil {
        switch interfaceOrientation {
        case UIInterfaceOrientation.portrait:
            previewLayerConnection?.videoOrientation = .portrait
        case UIInterfaceOrientation.landscapeRight:
            previewLayerConnection?.videoOrientation = .landscapeRight
        case UIInterfaceOrientation.landscapeLeft:
            previewLayerConnection?.videoOrientation = .landscapeLeft
        default:
            previewLayerConnection?.videoOrientation = .portrait
        }
    }

    view.layer.addSublayer(previewLayer)

0 个答案:

没有答案