When auto-rotation is disabled in portrait mode, placing device horizontally and tapping somewhere to focus causes preview layer to rotate. I did fix that by replacing this code:
if let connection = self.previewLayer?.videoPreviewLayer.connection {
let currentDevice: UIDevice = UIDevice.current
let orientation: UIDeviceOrientation = currentDevice.orientation
let previewLayerConnection : AVCaptureConnection = connection
if previewLayerConnection.isVideoOrientationSupported {
switch (orientation) {
case .portrait: updatePreviewLayer(layer: previewLayerConnection, orientation: .portrait)
break
case .landscapeRight: updatePreviewLayer(layer: previewLayerConnection, orientation: .landscapeLeft)
break
case .landscapeLeft: updatePreviewLayer(layer: previewLayerConnection, orientation: .landscapeRight)
break
case .portraitUpsideDown: updatePreviewLayer(layer: previewLayerConnection, orientation: .portraitUpsideDown)
break
default: updatePreviewLayer(layer: previewLayerConnection, orientation: .portrait)
break
}
}
}
with this:
if let previewLayerConnection = self.previewLayer?.videoPreviewLayer.connection {
let orientation = self.orientation.getPreviewLayerOrientation()
if previewLayerConnection.isVideoOrientationSupported {
updatePreviewLayer(layer: previewLayerConnection, orientation: orientation)
}
}
When auto-rotation is disabled in portrait mode, placing device horizontally and tapping somewhere to focus causes preview layer to rotate. I did fix that by replacing this code:
with this: