ZXing(Zebra Xing) Unable to scan/ detect the barcode in Xamarin iOS

匿名 (未验证) 提交于 2019-12-03 01:36:02

问题:

I posted couple other questions in regards to Zxing please DONT mark it duplicate just because they are about Zxing..

So, in my Xamarin iOS app, I am using Zxing to detect the barcode. I am using https://github.com/Redth/ZXing.Net.Mobile/tree/master/Samples/iOS as example.

I am using a subview to scan for barcodes. The custom overlay n everything works fine but it is unable to detect the barcode when I'm trying to scan. Can anyone please help me out where I'm doing wrong or missing something.

CODE

public UIView camView;          AVCaptureScannerView scannerView;         UIActivityIndicatorView loadingView;         UIView loadingBg;         UIView topBg;         UIView bottomBg;         MobileBarcodeScanner scanner;         public event Action<ZXing.Result> OnScannedResult;         public MobileBarcodeScanningOptions ScanningOptions { get; set; }  public override void ViewDidLoad()         {             camView = new UIView(new CGRect(0, 0, this.View.Frame.Width, this.View.Frame.Height / 3)) { BackgroundColor = UIColor.Clear };             scanner = new MobileBarcodeScanner();              Root = new RootElement("ZXingDwatNet.Mobile") {                 new Section {                       camView                 }             };              scannerView = new AVCaptureScannerView(camView.Frame);              camView = scannerView;              loadingBg = camView;// new UIView(this.View.Frame) { BackgroundColor = UIColor.Purple, AutoresizingMask = UIViewAutoresizing.FlexibleDimensions };             loadingView = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.White)             {                 AutoresizingMask = UIViewAutoresizing.FlexibleMargins             };             loadingView.Frame = new CGRect((this.View.Frame.Width - loadingView.Frame.Width) / 4,                 (this.View.Frame.Height - loadingView.Frame.Height) / 4,                 loadingView.Frame.Width / 4,                 loadingView.Frame.Height / 4);              loadingBg.AddSubview(loadingView);             View.AddSubview(loadingBg);             loadingView.StartAnimating();              this.View.InsertSubviewBelow(scannerView, loadingView);              this.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;           }          void HandleScanResult(ZXing.Result result)         {             string msg = "";              if (result != null && !string.IsNullOrEmpty(result.Text))                 msg = "Found Barcode: " + result.Text;             else                 msg = "Scanning Canceled!";              this.InvokeOnMainThread(() =>             {                 var av = new UIAlertView("Barcode Result", msg, null, "OK", null);                 av.Show();             });         }          public override void ViewDidAppear(bool animated)         {             //scannerView.OnScannerSetupComplete += HandleOnScannerSetupComplete;             //camView = scannerView;             var options = new MobileBarcodeScanningOptions             {                 AutoRotate = false,                 UseFrontCameraIfAvailable = false,                 TryHarder = true             };             ScanningOptions = options;              if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))             {                 UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.Default;                 SetNeedsStatusBarAppearanceUpdate();             }             else                 UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.BlackTranslucent, false);              Console.WriteLine("Starting to scan...");              Task.Factory.StartNew(() =>            {                BeginInvokeOnMainThread(() => scannerView.StartScanning(result =>                {                         //if (!ContinuousScanning)                        //{                        // Console.WriteLine("Stopping scan...");                        // scannerView.StopScanning();                        //}                         var evt = this.OnScannedResult;                    if (evt != null)                        evt(result);                 }, this.ScanningOptions));            });         }          void HandleOnScannerSetupComplete()         {             BeginInvokeOnMainThread(() =>            {                if (loadingView != null && loadingBg != null && loadingView.IsAnimating)                {                    loadingView.StopAnimating();                     UIView.BeginAnimations("zoomout");                     UIView.SetAnimationDuration(2.0f);                    UIView.SetAnimationCurve(UIViewAnimationCurve.EaseOut);                     loadingBg.Transform = CGAffineTransform.MakeScale(2.0f, 2.0f);                    loadingBg.Alpha = 0.0f;                     UIView.CommitAnimations();                      loadingBg.RemoveFromSuperview();                }            });         }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!