gpt4 book ai didi

ios - Xamarin Forms 中的 VNDocumentCameraViewController 卡住

转载 作者:行者123 更新时间:2023-12-01 21:18:25 25 4
gpt4 key购买 nike

我想使用新的 VNDocumentCameraViewController从带有自定义渲染器的我的 Xamarin Forms App 中的 iOS 13 开始。它可以工作,但有时几秒钟后,相机的预览会卡住,我没有机会在 View Controller 上做任何事情。
为了重现该错误,我将代码缩减为以下内容:
自定义 View :

public sealed class Scanner : View
{
}
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App1"
x:Class="App1.MainPage">
<local:Scanner />
</ContentPage>
自定义渲染器
[assembly: ExportRenderer(typeof(App1.Scanner), typeof(App1.iOS.ScannerRenderer))]

namespace App1.iOS
{
public class ScannerRenderer : ViewRenderer<Scanner, UIView>
{
protected override void OnElementChanged(ElementChangedEventArgs<Scanner> e)
{
base.OnElementChanged(e);

if (this.Control == null)
{
VNDocumentCameraViewController scannerController = new VNDocumentCameraViewController();
this.SetNativeControl(scannerController.View);
}
}
}
}
它主要发生在从左到右和向后快速移动相机时,但有时也没有做任何事情。
我没有找到任何人试图使用 VNDocumentCameraViewController与 Xamarin 形式。我做错了什么?还是有错误?

最佳答案

我找到了解决方案...我为此苦苦挣扎了两天,现在我发现垃圾收集器做了他的工作并摧毁了我的 scannerController一段时间后/叫 Dispose()VNDocumentCameraViewController .如果我将其更改为类(class)成员,它会起作用:
自定义渲染器

[assembly: ExportRenderer(typeof(App1.Scanner), typeof(App1.iOS.ScannerRenderer))]

namespace App1.iOS
{
public class ScannerRenderer : ViewRenderer<Scanner, UIView>
{
private VNDocumentCameraViewController scannerController;

protected override void OnElementChanged(ElementChangedEventArgs<Scanner> e)
{
base.OnElementChanged(e);

if (this.Control == null)
{
this.scannerController = new VNDocumentCameraViewController();
this.SetNativeControl(this.scannerController.View);
}
}
}
}

关于ios - Xamarin Forms 中的 VNDocumentCameraViewController 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63958302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com