Skip to content

Commit

Permalink
Merge pull request #43 from bhuvan94/fix_ios_camera_orientation
Browse files Browse the repository at this point in the history
Fix for iOS camera orientation issue
  • Loading branch information
Redth committed Oct 18, 2022
2 parents 4170b0f + b2cb405 commit aa7ca80
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ZXing.Net.MAUI/Apple/CameraManager.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using UIKit;
using Microsoft.Maui;
using MSize = Microsoft.Maui.Graphics.Size;
using CoreAnimation;

namespace ZXing.Net.Maui
{
Expand Down Expand Up @@ -254,8 +255,26 @@ public PreviewView(AVCaptureVideoPreviewLayer layer) : base()
public override void LayoutSubviews()
{
base.LayoutSubviews();
CATransform3D transform = CATransform3D.MakeRotation(0, 0, 0, 1.0f);
switch (UIDevice.CurrentDevice.Orientation)
{
case UIDeviceOrientation.Portrait:
transform = CATransform3D.MakeRotation(0, 0, 0, 1.0f);
break;
case UIDeviceOrientation.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);
break;
case UIDeviceOrientation.LandscapeRight:
transform = CATransform3D.MakeRotation((nfloat)Math.PI / 2, 0, 0, 1.0f);
break;
}

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

0 comments on commit aa7ca80

Please sign in to comment.