0

我正在使用 RedLaser 和 MonoTouch 开发一个简单的条码扫描应用程序。我已经使用了提供的示例代码,并且能够将我的代码部署到 iphone 并且它可以很好地扫描条形码。

但是,相机视图未显示。活动区域为空白。请看下面的图片 在此处输入图像描述

当我运行示例时,它工作正常。我猜这与连接视图和控制器有关

我的代码是这样的:

public partial class BarcodeScanModalController : CameraOverlayViewController
{
CAShapeLayer Rectanglelayer;
bool IsSilent;

public BarcodeScanModalController (IntPtr handle) : base (handle) 
{
}

public BarcodeScanModalController ()
{
}

internal void BeepOrVibrate ()
{
if (!IsSilent)
{
SystemSound.FromFile ("Sounds/beep.wav").PlayAlertSound ();
}
}

void setPortraitLayout ()
{
// Set portrait
ParentPicker.Orientation = UIImageOrientation.Up;
// Set the active scanning region for portrait mode
ParentPicker.ActiveRegion = new RectangleF (0, 100, 320, 250);
// Activate the new settings
ParentPicker.ResumeScanning ();
// Animate the UI changes
CGAffineTransform transform = CGAffineTransform.MakeRotation (0);
//this.View.Transform = transform;
UIView.BeginAnimations ("rotateToPortrait");
//UIView.SetAnimationDelegate = this;
UIView.SetAnimationCurve (UIViewAnimationCurve.Linear);
UIView.SetAnimationDuration (0.5f);

setActiveRegionRect ();
UIView.CommitAnimations (); // Animate!
}

CGPath newPathInRect (RectangleF rect)
{
CGPath path = new CGPath ();
path.AddRect (rect);
return path;
}
void setActiveRegionRect ()
{
Rectanglelayer.Frame = new RectangleF (    ParentPicker.ActiveRegion.X,
                                  ParentPicker.ActiveRegion.Y,
                                  ParentPicker.ActiveRegion.Width,
                                  ParentPicker.ActiveRegion.Height
);

CGPath path = newPathInRect (Rectanglelayer.Bounds);
Rectanglelayer.Path = path;
Rectanglelayer.SetNeedsLayout ();
}

然后我像这样使用这个 OverlayController:

public void ScanItemsButtonPressed (object sender, EventArgs e)
{
  if (overlayController == null)
{
overlayController = new BarcodeScanModalController {  ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal};
}

if (overlayController.ParentPicker == null)
{
BarcodePickerController picker = new BarcodePickerController ();
picker.Overlay = overlayController;
picker.Delegate = new BarcodePickerDelegate (this);
picker.Orientation = UIImageOrientation.Up;
}
overlayController.ParentPicker.ScanUPCE = true;
overlayController.ParentPicker.ScanEAN8 = true;
overlayController.ParentPicker.ScanEAN13 = true;
// overlayController.ParentPicker.ScanSTICKY = false;
overlayController.ParentPicker.ScanQRCODE = false;
overlayController.ParentPicker.ScanCODE128 = true;
overlayController.ParentPicker.ScanCODE39 = true;
overlayController.ParentPicker.ScanITF = true;
// Data matrix decoding does not work very well so it is disabled for now
overlayController.ParentPicker.ScanDATAMATRIX = false;
// hide the status bar
UIApplication.SharedApplication.StatusBarHidden = true;

overlayController.Done += delegate {
DismissModalViewControllerAnimated (true);
} ;

this.PresentModalViewController (overlayController.ParentPicker, true);
}

我正在使用 MonoTouch 6.0.8、RedLaser 3.4.0 和 XCode 4.5.2 任何帮助将不胜感激。谢谢

4

1 回答 1

0

这似乎是一个相当简单的问题。

背景颜色和 ActiveRegion FillColor 是全色(不透明),因此它位于相机视图的顶部。我可以通过将扫描视图的背景设置为无颜色(默认)并将 ActiveRegion 设置为透明的内容来解决该问题,如下所示。

RectangleLayer.FillColor = UIColor.FromRGBA(1.0f, 0.0f, 0.0f, 0.2f).CGColor;
于 2013-01-18T00:24:22.743 回答