Skip to content
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
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4.2.2
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4.1.0
with:
dotnet-version: '7.0.x'
- name: Setup NuGet 5.x
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
nuget sign .\artifacts\*.nupkg -CertificatePath $pfxPath -Timestamper http://timestamp.entrust.net/TSS/RFC3161sha2TS

- name: Artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4.4.3
with:
name: NuGet
path: ./artifacts
Expand All @@ -64,11 +64,11 @@ jobs:
if: github.event_name == 'release'
steps:
- name: Download Artifacts
uses: actions/download-artifact@v1
uses: actions/download-artifact@v4.1.8
with:
name: NuGet
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4.1.0
with:
dotnet-version: '7.0.x'
- name: Push NuGet
Expand Down
46 changes: 36 additions & 10 deletions ZXing.Net.MAUI/Apple/CameraManager.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal partial class CameraManager
AVCaptureVideoPreviewLayer videoPreviewLayer;
CaptureDelegate captureDelegate;
DispatchQueue dispatchQueue;
NSObject orientationObserver;
Dictionary<NSString, MSize> Resolutions => new()
{
{ AVCaptureSession.Preset352x288, new MSize(352, 288) },
Expand All @@ -43,11 +44,22 @@ public NativePlatformCameraPreviewView CreateNativeView()
videoPreviewLayer = new AVCaptureVideoPreviewLayer(captureSession);
videoPreviewLayer.VideoGravity = AVLayerVideoGravity.ResizeAspectFill;

// Observe device orientation changes to reapply layout subview
orientationObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OrientationChanged);

view = new PreviewView(videoPreviewLayer);

return view;
}

private void OrientationChanged(NSNotification notification)
{
if (view != null)
{
view.LayoutSubviews();
}
}

public void Connect()
{
UpdateCamera();
Expand Down Expand Up @@ -161,6 +173,13 @@ public void Disconnect()
captureDevice.Dispose();
captureDevice = null;
}

// Removing the orientationObserver
if (orientationObserver != null)
{
NSNotificationCenter.DefaultCenter.RemoveObserver(orientationObserver);
orientationObserver = null;
}
}
}

Expand All @@ -176,7 +195,7 @@ public void UpdateTorch(bool on)
{
CaptureDevicePerformWithLockedConfiguration(() =>
captureDevice.TorchMode = on ? AVCaptureTorchMode.On : AVCaptureTorchMode.Off);
}
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -258,26 +277,33 @@ public PreviewView(AVCaptureVideoPreviewLayer layer) : base()
public override void LayoutSubviews()
{
base.LayoutSubviews();

// Determine the UIInterfaceOrientation based on the current interface (application) orientation instead of the device orientation
UIInterfaceOrientation uiInterfaceOrientation = (UIInterfaceOrientation)UIApplication.SharedApplication.ConnectedScenes.ToArray()
.Select(x => x as UIWindowScene)
.LastOrDefault(x => x?.Windows != null && x.Windows.Any(y => y.IsKeyWindow))?.InterfaceOrientation;

CATransform3D transform = CATransform3D.MakeRotation(0, 0, 0, 1.0f);
switch (UIDevice.CurrentDevice.Orientation)

switch (uiInterfaceOrientation)
{
case UIDeviceOrientation.Portrait:
case UIInterfaceOrientation.Portrait:
transform = CATransform3D.MakeRotation(0, 0, 0, 1.0f);
break;
case UIDeviceOrientation.PortraitUpsideDown:
transform = CATransform3D.MakeRotation((nfloat)Math.PI, 0, 0, 1.0f);
case UIInterfaceOrientation.PortraitUpsideDown:
transform = CATransform3D.MakeRotation((nfloat)(Math.PI), 0, 0, 1.0f);
break;
case UIDeviceOrientation.LandscapeLeft:
transform = CATransform3D.MakeRotation((nfloat)(-Math.PI / 2), 0, 0, 1.0f);
case UIInterfaceOrientation.LandscapeLeft:
transform = CATransform3D.MakeRotation((nfloat)(Math.PI / 2), 0, 0, 1.0f);
break;
case UIDeviceOrientation.LandscapeRight:
transform = CATransform3D.MakeRotation((nfloat)Math.PI / 2, 0, 0, 1.0f);
case UIInterfaceOrientation.LandscapeRight:
transform = CATransform3D.MakeRotation((nfloat)(-Math.PI / 2), 0, 0, 1.0f);
break;
}

PreviewLayer.Transform = transform;
PreviewLayer.Frame = Layer.Bounds;
}
}
}
}
#endif