相机覆盖转到后台,活动区域前面是空白

时间:2013-01-17 06:26:02

标签: .net ios xcode xamarin.ios monodevelop

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

但是,相机视图未显示。活动区域为空白。请看下面的图片 enter image description here

当我运行样品时,它工作正常。我猜这与连接视图和控制器

有关

我的代码是这样的:

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 任何帮助将受到高度赞赏。感谢

1 个答案:

答案 0 :(得分:0)

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

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

RectangleLayer.FillColor = UIColor.FromRGBA(1.0f, 0.0f, 0.0f, 0.2f).CGColor;