Reputation: 57
I am building a Maui app which requires custom camera view/control in order to play some audio and show some more info.
What I have so far is working as it should in portrait mode. Once my phone is in landscape mode and I open the camera, the buttons on the bottom (back, record, audio) are visible but not clickable. The flash button does work on both scenario's. It seems like there is another layer on top of the other buttons. Does anyone know what to do?
public partial class CustomCameraOverlayView : UIView
{
public UIButton captureButton;
public UIButton cancelButton;
public UIButton flashButton;
public UIButton playAudioButton;
private UILabel countdownLabel;
private int countdownValue = 3;
private NSTimer countdownTimer;
private readonly AudioPlayer audioPlayer;
readonly UIImagePickerController picker;
readonly UIView overlay;
private UIView markerView;
private UIProgressView progressView;
private readonly double maximumTime; // Total time for 100% progress in seconds
private readonly double minimumTime;
private int currentProgress = 0;
private NSTimer progressTimer;
nfloat buttonX;
nfloat buttonY;
readonly int buttonWidth;
readonly int buttonHeight;
readonly EventHandler cancelAction;
bool _isRecording = false;
public CustomCameraOverlayView(double max, double min, AudioPlayer audioPlayer, UIImagePickerController picker, EventHandler cancelAction) : base(picker.CameraOverlayView.Frame)
{
maximumTime = max;
minimumTime = min;
countdownValue = int.Parse($"{min}");
this.audioPlayer = audioPlayer;
this.picker = picker;
overlay = new();
overlay.Frame = picker.CameraOverlayView.Frame;
this.cancelAction = cancelAction;
#region Remove black rect
nfloat ratio = (nfloat)4.0 / (nfloat)3.0;
nfloat scale;
if (DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait)
{
nfloat imageWidth = MathF.Floor((float)UIScreen.MainScreen.Bounds.Size.Width * (float)ratio);
scale = (nfloat)(Math.Ceiling(((float)UIScreen.MainScreen.Bounds.Size.Height / (float)imageWidth) * 10.0) / 10.0);
}
else
{
nfloat imageWidth = MathF.Floor((float)UIScreen.MainScreen.Bounds.Size.Height * (float)ratio);
scale = (nfloat)(Math.Ceiling(((float)UIScreen.MainScreen.Bounds.Size.Width / (float)imageWidth) * 10.0) / 10.0);
}
picker.CameraViewTransform = CGAffineTransform.MakeScale(scale, scale);
#endregion
buttonWidth = 60;
buttonHeight = 60;
buttonX = (UIScreen.MainScreen.Bounds.Width - buttonWidth) / 2;
buttonY = UIScreen.MainScreen.Bounds.Height - buttonHeight - 50;
GetXYPositions();
Initialize();
picker.CameraOverlayView = overlay;
}
void GetXYPositions()
{
if (DeviceDisplay.Current.MainDisplayInfo.Orientation == DisplayOrientation.Portrait)
{
buttonX = (UIScreen.MainScreen.Bounds.Width - buttonWidth) / 2;
buttonY = UIScreen.MainScreen.Bounds.Height - buttonHeight - 50;
}
else
{
buttonX = (UIScreen.MainScreen.Bounds.Height - buttonWidth) / 2;
buttonY = UIScreen.MainScreen.Bounds.Width - buttonHeight - 50;
//overlay.Transform = CGAffineTransform.MakeRotation((nfloat)Math.PI/2);
}
}
public void Initialize()
{
AddButtons();
AddProgressbar();
AddTimeCode();
//AddSubview(overlay);
}
void AddButtons()
{
// Cancel Button
cancelButton = UIButton.FromType(UIButtonType.Custom);
cancelButton.SetImage(new UIImage(NSBundle.MainBundle.PathForResource("back", "png")), UIControlState.Normal);
cancelButton.Frame = new CGRect(buttonX / 3, buttonY + 7, buttonWidth - 15, buttonHeight - 15);
cancelButton.TouchUpInside += cancelAction;
cancelButton.UserInteractionEnabled = true;
overlay.Add(cancelButton);
// Capture button
captureButton = UIButton.FromType(UIButtonType.Custom);
captureButton.SetImage(new UIImage(NSBundle.MainBundle.PathForResource("startrecording", "png")), UIControlState.Normal);
captureButton.Frame = new CGRect(buttonX, buttonY, buttonWidth, buttonHeight);
captureButton.TouchUpInside += CaptureButtonClicked;
captureButton.UserInteractionEnabled = true;
overlay.Add(captureButton);
if (audioPlayer != null)
{
// Audioplayer button
playAudioButton = UIButton.FromType(UIButtonType.Custom);
playAudioButton.SetImage(new UIImage(NSBundle.MainBundle.PathForResource("audio-msg", "png")), UIControlState.Normal);
playAudioButton.Frame = new CGRect((buttonX / 3) * 5 + 10, buttonY + 7, buttonWidth - 15, buttonHeight - 15);
playAudioButton.TouchUpInside += PlayAudioBtnClicked;
playAudioButton.UserInteractionEnabled = true;
audioPlayer.AudioPlayerInstance.FinishedPlaying += FinishedPlaying;
overlay.Add(playAudioButton);
}
// Flash button
flashButton = UIButton.FromType(UIButtonType.Custom);
flashButton.SetImage(new UIImage(NSBundle.MainBundle.PathForResource("flash-off", "png")), UIControlState.Normal);
var flashButtonY = 20;
flashButton.Frame = new CGRect(buttonX / 6, flashButtonY, buttonWidth - 15, buttonHeight - 15);
flashButton.TouchUpInside += FlashButtonClicked;
flashButton.UserInteractionEnabled = true;
overlay.Add(flashButton);
}
}
Upvotes: 0
Views: 165