How to make Zebra Xing (Zxing) customs overlay as subview in Xamarin iOS

ASyedASyed USMember ✭✭

Hi,

I want to scan a barcode and return the result. I'm using ZXing for that. For Zxing when its default overlay, it would navigate to a new page and scan works perfectly. I want to stay on the same page and want a subview to enable camera and start scanning. Can anyone advise how to do that?

MyCode:

var scanner = new ZXing.Mobile.MobileBarcodeScanner();
            scanner.UseCustomOverlay = true;
            scanner.CustomOverlay = this.View.ScanView;//ScanView is a subview on my current view

            Task.Run(
                async () =>
                {
                    var result = await scanner.Scan();
                    HandleScanResult(result);
                });

Answers

  • AroshaCreativeAroshaCreative Member ✭✭
            private ZXingScannerView m_scannerView;
    
            var mobileBarcodeScanner = new MobileBarcodeScanner(this);
            m_scannerView =
                new ZXingScannerView(
                    new CGRect(
                        0,
                        0,
                        m_findPatientsView.CustomScannerView.ScannerView.Frame.Width,
                        m_findPatientsView.CustomScannerView.ScannerView.Frame.Height))
                {
                    AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
                    UseCustomOverlayView = mobileBarcodeScanner.UseCustomOverlay,
                    CustomOverlayView = mobileBarcodeScanner.CustomOverlay
                };
    
        // Adding scanner view as a subview
            m_findPatientsView.CustomScannerView.ScannerView.Add(m_scannerView);
    
            m_scannerView.StartScanning(
                async result =>
                {
                    if (result != null)
                    {
                        // Handle scaneed result
                    }
                });
    
Sign In or Register to comment.