imaginary-cloud / CameraManager

Simple Swift class to provide all the configurations you need to create custom camera view in your app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Preview rotated by 90 degrees.

scdanieli opened this issue · comments

When I add the preview layer to a view while the the physical device is in landscape the preview layer is rotated by 90 degrees.

If I change the _currentVideoOrientation() function to

fileprivate func _currentVideoOrientation() -> AVCaptureVideoOrientation { return .portrait }

everything seems to work as expected, but that fix just seems very hacky, so I was wondering if this may be a bug or if I'm doing anything wrong!?

I should probably mention that I only support the portrait orientation in my app and I'm pretty sure this has something to do with it.

I have a similar problem, I support only portrait in whole app except inside the "video recorder" section, where i support both landscape orientations. If i set camera.shouldRespondToOrientationChanges = true the camera follows the orientation when the device is portrait. I think (but not completely sure) the AVCaptureVideoOrientation should be derived from UIInterfaceOrientation/UITraitCollection instead of UIDeviceOrientation inside _currentVideoOrientation() -> AVCaptureVideoOrientation

_currentVideoOrientation() -> AVCaptureVideoOrientation implementation should be

switch UIApplication.shared.statusBarOrientation {
case .landscapeLeft: return .landscapeLeft
case .landscapeRight: return .landscapeRight
default: return .portrait
}

instead of

   switch UIDevice.current.orientation {
        case .landscapeLeft:
            return .landscapeRight
        case .landscapeRight:
            return .landscapeLeft
        default:
            return .portrait
   }