我正在使用 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 任何帮助将不胜感激。谢谢