我制作了一个Xamarin.iOS应用程序,我有一个摄像头流。 在我的故事板中,我有一个UIButton可以拍照,一个可以切换相机。
但是当我启动我的应用程序时,按钮位于相机流下。
有人知道如何将按钮放在相机流上吗?
这是我的代码
public override void ViewDidLoad()
{
base.ViewDidLoad();
liveCameraStream = PhotoView;
SetupLiveCameraStream();
}
public void SetupLiveCameraStream()
{
captureSession = new AVCaptureSession();
var viewLayer = liveCameraStream.Layer;
var videoPreviewLayer = new AVCaptureVideoPreviewLayer(captureSession)
{
Frame = liveCameraStream.Bounds
};
liveCameraStream.Layer.AddSublayer(videoPreviewLayer);
var captureDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
ConfigureCameraForDevice(captureDevice);
captureDeviceInput = AVCaptureDeviceInput.FromDevice(captureDevice);
var dictionary = new NSMutableDictionary();
dictionary[AVVideo.CodecKey] = new NSNumber((int)AVVideoCodec.JPEG);
stillImageOutput = new AVCaptureStillImageOutput()
{
OutputSettings = new NSDictionary()
};
captureSession.AddOutput(stillImageOutput);
captureSession.AddInput(captureDeviceInput);
captureSession.StartRunning();
}
答案 0 :(得分:1)
此处liveCameraStream
视图悬停在按钮上方,因此我们必须在视图层次结构中将其发回,以便可以查看按钮。
以下任何一项都适合您:
// 1
UIView cameraView = new UIView(videoPreviewLayer.Frame);
cameraView.Layer.AddSublayer(videoPreviewLayer);
View.AddSubview(cameraView);
View.SendSubviewToBack(cameraView);
-------OR-------
// 2
liveCameraStream.Layer.AddSublayer(videoPreviewLayer);
View.SendSubviewToBack(liveCameraStream);
用以上代码行替换以下行:
liveCameraStream.Layer.AddSublayer(videoPreviewLayer);
修改强>
第二个选项适合这篇文章。