public override void ViewDidLoad() { base.ViewDidLoad(); // The scanning behavior of the barcode picker is configured through scan // settings. We start with empty scan settings and enable a generous set // of 1D symbologies. Matrix scan is currently only supported for 1D // symbologies, enabling 2D symbologies will result in unexpected results. // In your own apps, only enable the symbologies you actually need. ScanSettings settings = ScanSettings.DefaultSettings(); NSSet symbologiesToEnable = new NSSet( Symbology.EAN13, Symbology.EAN8, Symbology.UPC12, Symbology.UPCE, Symbology.Code39, Symbology.Code128, Symbology.ITF ); // Enable matrix scan and set the max number of barcodes that can be recognized per frame // to some reasonable number for your use case. The max number of codes per frame does not // limit the number of codes that can be tracked at the same time, it only limits the // number of codes that can be newly recognized per frame. settings.EnableSymbologies(symbologiesToEnable); settings.MatrixScanEnabled = true; settings.MaxNumberOfCodesPerFrame = 10; settings.HighDensityModeEnabled = true; // When matrix scan is enabled beeping/vibrating is often not wanted. BarcodePicker picker = new BarcodePicker(settings); picker.OverlayView.SetBeepEnabled(false); picker.OverlayView.SetVibrateEnabled(false); // Register a SBSScanDelegate delegate, in order to be notified about relevant events // (e.g. a successfully scanned bar code). scanDelegate = new PickerScanDelegate(); picker.ScanDelegate = scanDelegate; // Register a SBSProcessFrameDelegate delegate to be able to reject tracked codes. processFrameDelegate = new PickerProcessFrameDelegate(); picker.ProcessFrameDelegate = processFrameDelegate; AddChildViewController(picker); picker.View.Frame = View.Bounds; Add(picker.View); picker.DidMoveToParentViewController(this); picker.OverlayView.GuiStyle = GuiStyle.MatrixScan; picker.StartScanning(); }
public override void ViewDidLoad() { base.ViewDidLoad(); // The scanning behavior of the barcode picker is configured through scan // settings. We start with empty scan settings and enable a very generous // set of symbologies. In your own apps, only enable the symbologies you // actually need. ScanSettings settings = ScanSettings.DefaultSettings(); NSSet symbologiesToEnable = new NSSet( Symbology.EAN13, Symbology.EAN8, Symbology.UPC12, Symbology.UPCE, Symbology.Datamatrix, Symbology.QR, Symbology.Code39, Symbology.Code128, Symbology.ITF ); settings.EnableSymbologies(symbologiesToEnable); // Enable and set the restrict active area. This will make sure that codes are only scanned in a very thin band in the center of the image. settings.SetActiveScanningArea(new CoreGraphics.CGRect(0, 0.48, 1, 0.04)); // Setup the barcode scanner picker = new BarcodePicker(settings); picker.OverlayView.ShowToolBar(false); // Add delegate for the scan event. We keep references to the // delegates until the picker is no longer used as the delegates are softly // referenced and can be removed because of low memory. scanDelegate = new PickerScanDelegate(); picker.ScanDelegate = scanDelegate; AddChildViewController(picker); picker.View.Frame = View.Bounds; Add(picker.View); picker.DidMoveToParentViewController(this); // Modify the GUI style to have a "laser" line instead of a square viewfinder. picker.OverlayView.GuiStyle = GuiStyle.Laser; // Start scanning in paused state. picker.StartScanning(true); showAimAndScanButton(); }
public override void ViewDidLoad() { base.ViewDidLoad(); contatinerView = new UIView(CGRect.Empty); View.AddSubview(contatinerView); freezeButton = new UIButton(CGRect.Empty); freezeButton.SetTitle("Freeze", UIControlState.Normal); freezeButton.SetBackgroundImage(UIImageExtensions.Brand.GetImage(), UIControlState.Normal); freezeButton.TouchUpInside += (sender, e) => { var scanning = picker.IsScanning(); if (scanning) { matrixScanHandler.Enabled = false; picker.PauseScanning(); freezeButton.SetTitle("Done", UIControlState.Normal); } else { matrixScanHandler.RemoveAllAugmentations(); matrixScanHandler.Enabled = true; picker.StartScanning(); freezeButton.SetTitle("Freeze", UIControlState.Normal); } }; View.AddSubview(freezeButton); freezeButton.TranslatesAutoresizingMaskIntoConstraints = false; contatinerView.TranslatesAutoresizingMaskIntoConstraints = false; View.AddConstraints(new[] { contatinerView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor), contatinerView.TopAnchor.ConstraintEqualTo(View.TopAnchor), contatinerView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor), contatinerView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor), freezeButton.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor, 20), freezeButton.BottomAnchor.ConstraintEqualTo(View.BottomAnchor, -20), freezeButton.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor, -20), freezeButton.HeightAnchor.ConstraintEqualTo(60) }); var settings = ScanSettings.DefaultSettings(); settings.SetSymbologyEnabled(Symbology.EAN13, true); settings.MatrixScanEnabled = true; settings.MaxNumberOfCodesPerFrame = 15; settings.HighDensityModeEnabled = true; picker = new BarcodePicker(settings); picker.OverlayView.GuiStyle = GuiStyle.None; matrixScanHandler = new MatrixScanHandler(picker); matrixScanHandler.ShouldReject += (matrixScanHandler, trackedBarcode) => false; // This delegate method is called every time a new frame has been processed. // In this case we use it to update the offset of the augmentation. matrixScanHandler.DidProcess += (sender, e) => { DispatchQueue.MainQueue.DispatchAsync(() => { foreach (var item in e.Frame.TrackedCodes) { var offset = GetYOffSet(item.Value as TrackedBarcode); viewBasedMatrixScanOverlay.SetOffset(offset, item.Key as NSNumber); } }); }; viewBasedMatrixScanOverlay = new ViewBasedMatrixScanOverlay(); // This method is called every time a new barcode has been tracked. // You can implement this method to return the offset that will be used to position the augmentation // with respect to the center of the tracked barcode. viewBasedMatrixScanOverlay.OffsetForOverlay += (overlay, barcode, identifier) => GetYOffSet(barcode); // This delegate method is called every time a new barcode has been tracked. // You can implement this method to return the view that will be used as the augmentation. viewBasedMatrixScanOverlay.ViewForOverlay += (overlay, barcode, identifier) => { if (barcode.Data == null) { return(new UIView(CGRect.Empty)); } var view = new StockView(new CGRect(0, 0, StockView.StandardWidth, StockView.StandardHeight)); var model = Model.MockedModel(barcode.Data); view.AddGestureRecognizer(new UITapGestureRecognizer(() => { var overlayViewController = new OverlayViewController { Model = model, ModalTransitionStyle = UIModalTransitionStyle.CoverVertical, ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext }; PresentViewController(overlayViewController, false, null); })); view.Model = model; return(view); }; // Add a ViewBasedMatrixScanOverlay in order to have custom UIView instances as augmentations. matrixScanHandler.AddOverlay(viewBasedMatrixScanOverlay); simpleMatrixScanOverlay = new SimpleMatrixScanOverlay(); // This method is called every time a new barcode has been tracked. // You can implement this method to customize the color of the highlight. simpleMatrixScanOverlay.ColorForOverlay += (overlay, barcode, identifier) => Model.MockedColor(barcode.Data); // Add a SimpleMatrixScanOverlay in order to highlight the barcodes. matrixScanHandler.AddOverlay(simpleMatrixScanOverlay); AddChildViewController(picker); picker.View.Frame = contatinerView.Frame; picker.View.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth; contatinerView.AddSubview(picker.View); picker.DidMoveToParentViewController(this); picker.StartScanning(); }