janusw / Camera.Maui

A CameraView Control for .NET Maui
MIT License
18 stars 3 forks source link

Camera preview on iOS sometimes rotated in landscape orientation #19

Closed janusw closed 6 months ago

janusw commented 6 months ago

To reproduce (with version 1.4.7):

  1. Open the Camera.MAUI.Test app on an iOS device, tap "Go to MVVM Cam".
  2. Hold the device in landscape orientation, with the camera pointing forward. The preview is oriented correctly.
  3. Rotate the device downwards, so that the camera points towards the floor. The preview is now rotated by 90°.
janusw commented 6 months ago

I think the origin of the bug is this piece of code:

https://github.com/janusw/Camera.Maui/blob/b6b36830b8456a2d034a14b2e209c0303da565a5/Camera.MAUI/Apple/MauiCameraView.cs#L588-L608

The UIDeviceOrientation enum, which is used here, also includes the cases faceUp and faceDown, which are not handled in the above snippet. This seems to be the reason for the misbehavior: If the device is in faceUp or faceDown mode, the rotation of the preview is not determined correctly.

The best solution is probably to use UIInterfaceOrientation instead of UIDeviceOrientation. This does not include faceUp/faceDown, and in fact it's not relevant how the device itself is oriented, but rather how the app on the device is oriented.

janusw commented 6 months ago

Some links: