public override void ViewDidLoad() { base.ViewDidLoad(); // Initializing the License Plate module. CGRect frame = UIScreen.MainScreen.ApplicationFrame; frame = new CGRect(frame.X, frame.Y + NavigationController.NavigationBar.Frame.Size.Height, frame.Width, frame.Height - NavigationController.NavigationBar.Frame.Size.Height); _scanView = new AnylineLicensePlateModuleView(frame); // important: set up the scanView with the license key BEFORE calling CopyTrainedData, else it will fail! // We tell the module to bootstrap itself with the license key and delegate. The delegate will later get called // by the module once we start receiving results. _error = null; _success = _scanView.SetupWithLicenseKey(_licenseKey, Self, out _error); // SetupWithLicenseKey:delegate:error returns true if everything went fine. In the case something wrong // we have to check the error object for the error message. if (!_success) { // Something went wrong. The error object contains the error description (Alert = new UIAlertView("Error", _error.DebugDescription, (IUIAlertViewDelegate)null, "OK", null)).Show(); } // We stop scanning manually _scanView.CancelOnResult = false; // After setup is complete we add the module to the view of this view controller View.AddSubview(_scanView); /* * The following view will present the scanned values. Here we start listening for taps * to later dismiss the view. */ _resultView = new LicensePlateResultOverlayView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height), UIImage.FromBundle(@"drawable/license_plate_background.png")); _resultView.AddGestureRecognizer(new UITapGestureRecognizer(this, new ObjCRuntime.Selector("ViewTapSelector:"))); _resultView.Center = View.Center; _resultView.Alpha = 0; _resultView.Result.Center = new CGPoint(View.Center.X, View.Center.Y); _resultView.Result.Font = UIFont.BoldSystemFontOfSize(27); _resultView.Result.TextColor = UIColor.Black; _resultView.Country.Center = new CGPoint(View.Center.X - 136, View.Center.Y + 13); _resultView.Country.Font = UIFont.BoldSystemFontOfSize(16); _resultView.Country.TextColor = UIColor.White; View.AddSubview(_resultView); }
/* * This is the main delegate method Anyline uses to report its results */ void IAnylineLicensePlateModuleDelegate.DidFindResult(AnylineLicensePlateModuleView anylineLicensePlateModuleView, ALLicensePlateResult scanResult) { StopAnyline(); if (_resultView != null) { View.BringSubviewToFront(_resultView); } var country = scanResult.Country; var textResult = scanResult.Result.ToString(); _resultView?.UpdateResult(textResult); _resultView?.UpdateCountry(country); // Present the information to the user _resultView?.AnimateFadeIn(View); }
new void Dispose() { //un-register any event handlers here, if you have any //we have to erase the scan view so that there are no dependencies for the viewcontroller left. //remove result view _resultView?.RemoveFromSuperview(); _resultView?.Dispose(); _resultView = null; //we have to erase the scan view so that there are no dependencies for the viewcontroller left. _scanView?.RemoveFromSuperview(); _scanView?.Dispose(); _scanView = null; GC.Collect(GC.MaxGeneration); base.Dispose(); }