Skip to content

Commit

Permalink
Merge pull request mrousavy#2 from flip-shop/iphone_15_support
Browse files Browse the repository at this point in the history
iPhone 15 support fix
  • Loading branch information
DominikHinc authored Oct 2, 2023
2 parents 8833ac1 + 62d5ce4 commit 9615368
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion ios/CameraView+Orientation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,39 @@

import Foundation
import UIKit
import AVFoundation

extension CameraView {

private func interfaceOrientation(from: UIDeviceOrientation) -> UIInterfaceOrientation {
switch (from) {
case .landscapeLeft:
return .landscapeRight
case .landscapeRight:
return .landscapeLeft
case .portraitUpsideDown:
return .portraitUpsideDown
default:
return .portrait
}
}

private func captureVideoOrientation(from: UIInterfaceOrientation) -> AVCaptureVideoOrientation {
switch (from) {
case .landscapeLeft:
return .landscapeLeft
case .landscapeRight:
return .landscapeRight
case .portraitUpsideDown:
return .portraitUpsideDown
default:
return .portrait
}
}

/// Orientation of the input connection (preview)
private var inputOrientation: UIInterfaceOrientation {
return .portrait
return self.interfaceOrientation(from: UIDevice.current.orientation)
}

// Orientation of the output connections (photo, video, frame processor)
Expand Down Expand Up @@ -41,5 +69,16 @@ extension CameraView {
connection.setInterfaceOrientation(connectionOrientation)
}
}

// update the preview layer orientation when the user rotates the device
// adapted from https://stackoverflow.com/a/36575423
DispatchQueue.main.async {
if let previewLayerConnection: AVCaptureConnection = self.videoPreviewLayer.connection {
if previewLayerConnection.isVideoOrientationSupported {
previewLayerConnection.videoOrientation = self.captureVideoOrientation(from: connectionOrientation)
self.videoPreviewLayer.frame = self.bounds
}
}
}
}
}

0 comments on commit 9615368

Please sign in to comment.