ZXing.Mobile.MobileBarcodeScanner.Cancel() 不起作用 [英] ZXing.Mobile.MobileBarcodeScanner.Cancel() not working

查看:31
本文介绍了ZXing.Mobile.MobileBarcodeScanner.Cancel() 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Visual Studio 上的 Xamarin Forms 上开发一个适用于 UWP、Android 和 IOS 的移动应用程序.

I'm developing a mobile application on Xamarin Forms for UWP, Android and IOS on Visual Studio.

我目前正在我的计算机(Windows 10)和我的手机(也是 Windows 10)上测试该应用.

I'm currently testing the app on my computer(Windows 10) and my phone (also Windows 10).

我正在使用 Zxing MobileBarcodeScanner 扫描多个条码.

I'm using Zxing MobileBarcodeScanner to scan multiple barcodes.

当我按下后退按钮时,我调用 MobileBarcodeScanner.Cancel().

When i press the back button i call the MobileBarcodeScanner.Cancel().

它唯一能做的就是关闭相机.它没有废弃 MobileBarcodeScanner 的 UI,我也没有找到任何解决方案.

The only thing that it does is to close the camera. It doesn't depose the MobileBarcodeScanner's UI and i didn't found any solution for that.

有人可以帮助我或提出解决方案吗?

Can anyone help me or suggest a solution?

此外,取消按钮和闪光按钮也不会显示在扫描仪 UI 中.

Also the Cancel Button and the Flash Button aren't shown to the scanner UI.

代码:

private void showScanner()
{
    var scanner = new MobileBarcodeScanner(App.coreDispatcher)
    {
        UseCustomOverlay = false,
        TopText = "Hold camera up to barcode to scan",
        BottomText = "Barcode will automatically scan",
        CancelButtonText = "Done",
        FlashButtonText = "Flash"
    }

    var opt = new MobileBarcodeScanningOptions { DelayBetweenContinuousScans = 3000 };

    scanner.ScanContinuously(opt, HandleScanResult);
}

protected override bool OnBackButtonPressed()
{
    scanner.Cancel();
}

private void HandleScanResult(ZXing.Result result)
{
    string msg;
    if (result != null && !string.IsNullOrEmpty(result.Text)) // Success
    {
        msg = result.Text;
    }
    else // Canceled
    {
        msg = "Scanning Canceled!";
    }
}

推荐答案

它唯一能做的就是关闭相机.它没有废弃 MobileBarcodeScanner 的 UI,我也没有找到任何解决方案

The only thing that it does is to close the camera. It doesn't depose the MobileBarcodeScanner's UI and i didn't found any solution for that

您的代码片段存在问题.在 showScanner() 方法中,您定义了一个 scanner 变量,但在 OnBackButtonPressed() 方法中,您似乎使用了一个也称为 scanner 的全局变量.

There is an issue in your code snippets. In the showScanner() method, you have defined a scanner variable, but in OnBackButtonPressed() method, looks like you have used a global variable also called scanner.

也许以下方式应该是正确的:

Maybe the following way should be correct:

MobileBarcodeScanner scanner;

private void showScanner(){
    scanner = new MobileBarcodeScanner(App.coreDispatcher) //Here, remove var
    {
        ......
    }

}
protected override bool OnBackButtonPressed()
{
    scanner.Cancel();
}

如果您查看了 Xamarin.Forms 示例

它使用 ZXingScannerPage 来托管您的布局并处理一些逻辑,包括 Cancel 和 ToggleTorch 等,请参阅 这里

It uses the ZXingScannerPage to host your layout and handle some logics, including Cancel and ToggleTorch etc, see here

此外,取消按钮和闪光按钮也不会显示在扫描仪 UI 中.

Also the Cancel Button and the Flash Button aren't shown to the scanner UI.

请使用自定义叠加,只需将 MobileBarcodeScanner.UseCustomOverlay 属性设置为 true 并检查 此处

Please use Custom Overlay, just set MobileBarcodeScanner.UseCustomOverlay property to true and check the sample code in here

还有 ZXing.Net.Mobile 入门

这篇关于ZXing.Mobile.MobileBarcodeScanner.Cancel() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆