我正在尝试解决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)