Skip to content

fix(iPad): correct photo rotation in landscape mode #6086 #6089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Signal/src/ViewControllers/Photos/CameraCaptureSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ class CameraCaptureSession: NSObject {
}

private var motionManager: CMMotionManager?

// Allows external callers to update capture orientation on the session queue.
// Useful for iPads deriving orientation from interface, especially before accelerometer data is available.
func setCaptureOrientation(_ orientation: AVCaptureVideoOrientation) {
sessionQueue.async { [weak self] in
self?.captureOrientation = orientation
self?.updateVideoCaptureOrientation()
}
}

func updateVideoPreviewConnection(toOrientation orientation: AVCaptureVideoOrientation) {
guard let videoConnection = previewView.previewLayer.connection else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ class PhotoCaptureViewController: OWSViewController, OWSNavigationChildControlle
previewOrientation = .portrait
}
UIViewController.attemptRotationToDeviceOrientation()

// Updates preview layer and capture orientation for correct media encoding.
// Crucial on iPad where interface orientation may differ from default portrait.
cameraCaptureSession.updateVideoPreviewConnection(toOrientation: previewOrientation)
cameraCaptureSession.setCaptureOrientation(previewOrientation)
updateIconOrientations(isAnimated: false, captureOrientation: previewOrientation)

NotificationCenter.default.addObserver(
Expand Down