在整合zxing for iPhone时管理视图 [英] Managing views while integrating zxing for iPhone

查看:76
本文介绍了在整合zxing for iPhone时管理视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 zxing 整合到我现有的iPhone应用中。我已经参考了项目下载中附带的ScanTest示例,并成功构建并运行了扫描程序。

I am trying to integrate zxing in my already existing iPhone app. I have referred to the ScanTest example enclosed in the project download, and have succeeded in building and running the scanner.

我的问题在于管理项目的视图以便合并扫描仪。目前我有一个已经存在的视图控制器(VC-A),它需要扫描仪功能。我创建了一个新的视图控制器(VC-B)来启动 ZXingWidgetController 扫描器视图。所以流程如下所示:

My problem lies in managing the views of the project to incorporate the scanner. Currently I have an already existing view controller(VC-A), which needs the scanner ability. I created a new view controller(VC-B) to launch the ZXingWidgetController scanner view. So the flow looks like the following:


VC-A-> presentModalViewController(VC-B) - > VC-B->
presentModalViewController(ZXingWidgetController)

VC-A-> presentModalViewController(VC-B)->VC-B-> presentModalViewController(ZXingWidgetController)

现在在ScanTest示例应用程序中,扫描完成时,从VC调用dissmissModalViewController -B解除了ZXingWidgetController的视图。问题是我尝试的任何方式,我无法解雇VC-B回到VC-A。当扫描完成/取消时,我创建了一组委托方法来通知VC-A。我在这些方法中获取扫描数据,但无法忽略VC-B的视图。

Now as is in the ScanTest sample application, when the scanning is complete, a dissmissModalViewController is called from VC-B which dismisses ZXingWidgetController's view. The problem is whatever way I try, I am unable to dismiss VC-B to come back to VC-A. I have created a set of delegate methods to notify VC-A, when the scanning is completed/canceled. I get the scan data in those methods, but am unable to dismiss VC-B's view.

我不想修改我现有的视图控制器VC-A,因此我无法直接在其中合并ZXingWidgetController,完全丢弃VC-B(因为它需要制作VC-A .mm文件)。

I don't want to modify my already existing view controller VC-A, therefore I am unable to incorporate ZXingWidgetController directly in it, discarding VC-B altogether(cause it would require making VC-A a .mm file).

编辑:
现在我完全放弃了ZXingWidgetController的模态。在VC-B上的 viewDidLoad 中使用此代码

//Create custom overlay
OverlayView *scannerView = [[OverlayView alloc]initWithFrame:CGRectMake(27, 107, 267, 253) cancelEnabled:NO oneDMode:NO];
scannerView.displayedMessage = nil;
widController = [[ZXingWidgetController alloc]init ];

//set the overlay of widController
[widController setOverlayView:scannerView];

QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil];
[qrcodeReader release];
widController.readers = readers;
widController.delegate = self;
[readers release];
[scannerView release];
NSBundle *mainBundle = [NSBundle mainBundle];
widController.soundToPlay = [NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO];

//Add scanner to the view
  [self.view addSubview:widController.view];

现在根本看不到ZXingWidgetController的摄像机视图。有人为Zxing定制了叠加层吗?我似乎没有在SO上发现任何类似的问题。

Now the camera view of ZXingWidgetController is not visible at all. Has anyone customized the overlay for Zxing? I don't seem to find any similar problem on SO.

推荐答案

使用ZXing,您可以直接访问叠加视图并添加/更改其子视图。例如,将imageview置于此概述之上,如下所示:

With ZXing you can access the overlay view directly and add/change its subviews. For example, putting an imageview on top of this overview is done as follows:

ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];

UIImage *qrOverlayImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"overlay-image" ofType:@"png"]];

UIImageView *qrOverlayImageView = [[[UIImageView alloc] initWithImage:qrOverlayImage] autorelease];
qrOverlayImageView.contentMode = UIViewContentModeScaleAspectFit;
qrOverlayImageView.backgroundColor = [UIColor clearColor];

[widController.overlayView addSubview:qrOverlayImageView];

使用具有透明度的PNG,添加UILabels等以编程方式创建自定义叠加层。

Use PNGs with transparency, add UILabels etc to create your custom overlay programmatically.

这篇关于在整合zxing for iPhone时管理视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆