我发布了关于Zxing的其他几个问题,请 DONT 将它标记为重复只是因为它们是关于Zxing ..
所以,在我的Xamarin iOS应用程序中,我使用Zxing来检测条形码。我使用https://github.com/Redth/ZXing.Net.Mobile/tree/master/Samples/iOS作为示例。
我正在使用子视图扫描条形码。自定义覆盖n一切正常但在我尝试扫描时无法检测到条形码。 任何人都可以帮助我解决我做错或丢失的事情。
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();
}
});
}