Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Conversation

@frosty
Copy link
Contributor

@frosty frosty commented Mar 14, 2017

Fixes #135.

The camera preview image was getting flipped when holding the device in portrait and then tilting it forward (as though you were going to point it downwards). This seemed to be because we were casting UIDeviceOrientation directly to AVCaptureVideoOrientation, but AVCaptureVideoOrientation has two extra Face Up / Face Down cases that the AV enum doesn't have. To fix the issue, we convert either of those cases to AVCaptureVideoOrientationPortrait.

To test:

  • Run on a device
  • Open the picker and look at the camera preview cell
  • Hold the device in portrait
  • Slowly tilt the device forward until you're pointing the camera down at the floor. Check the preview image is still orientated correctly
  • Check that landscape orientations still work correctly too.

Needs review: @SergioEstevao

@frosty frosty added the bug label Mar 14, 2017
@frosty frosty added this to the 0.13 milestone Mar 14, 2017
@frosty frosty requested a review from SergioEstevao March 14, 2017 10:08
Copy link
Member

@koke koke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you set the phone to landscape, then point it down, the preview will turn to portrait.

I think the underlying problem is that we don't want to look at device orientation, but adjust the preview orientation to the interface orientation: regardless of the actual position of the phone, only show landscape if the UI is landscape.

return AVCaptureVideoOrientationPortrait;
}

return (AVCaptureVideoOrientation)orientation;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AVCaptureVideoOrientation can't be directly mapped to UIDeviceOrientation, as their values are different.

@frosty
Copy link
Contributor Author

frosty commented Mar 14, 2017

Thanks @koke, I hadn't thought about landscape using face down orientation too. I've switched things over to use the interface orientation, as you suggested, and I've explicitly mapped to the correct values.

Better?

Copy link
Contributor

@SergioEstevao SergioEstevao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working great @frosty. :shipit:

@frosty frosty merged commit ec31817 into develop Mar 14, 2017
@frosty
Copy link
Contributor Author

frosty commented Mar 14, 2017

Thanks @SergioEstevao and @koke!

@frosty frosty deleted the issue/135-capture-orientation branch March 14, 2017 14:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Camera preview orientation incorrect when tilted forward

4 participants