2012-07-23 33 views
0

我正在使用Zbar扫描仪SDK,它可以让我读取条形码。现在,默认版本在读取一个条形码后停止扫描并显示结果。我用自己的Done按钮创建了自己的UIToolBar,因为我希望它多次扫描,只要用户点击我的UIToolBar上的“完成”按钮,所有这些都将被终止。我已经制作了按钮,但是如何将操作添加到按钮?由于pickerController的参与和Zbar SDK,这是相当混乱的。我如何将覆盖层中的doneButton链接到终止扫描的操作?如何使用自定义按钮消除UImagePickerController的视图?

这是我已经设置完成按钮的覆盖。

-(UIView*)CommomOverlay { 

UIToolbar *myToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 428, 320, 70)]; 
[myToolBar setBarStyle:UIBarStyleBlackTranslucent]; 

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonTap:)]; 

[myToolBar setItems:[NSArray arrayWithObjects:doneButton, nil] animated:YES]; 
[FrameImg addSubview:myToolBar]; 
[view addSubview:FrameImg]; 
return view; 

这是条码扫描器SDK的IPC部分。

-(void) imagePickerController: (UIImagePickerController*) 
readerdidFinishPickingMediaWithInfo: (NSDictionary*) info { 
{ 

// ADD: get the decode results 
id<NSFastEnumeration> results = 
[info objectForKey: ZBarReaderControllerResults]; 
ZBarSymbol *symbol = nil; 
for(symbol in results) 
// EXAMPLE: just grab the first barcode 
break; 
// EXAMPLE: do something useful with the barcode data 
resultText.text = symbol.data; 

// setup our custom overlay view for the camera 
// ensure that our custom view's frame fits within the parent frame 
// EXAMPLE: do something useful with the barcode image 
resultImage.image = 
[info objectForKey: UIImagePickerControllerOriginalImage]; 

// ADD: dismiss the controller (NB dismiss from the *reader*!) 
//Delete below in entirety for continuous scanning. 
[reader dismissModalViewControllerAnimated: NO]; 
} 
+0

您是否尝试过使用选择 – 2012-07-23 05:34:39

+0

让我知道设置dissmissmodalviewcontroller的动作上完成的按钮如果它工作 – 2012-07-23 05:36:53

+0

您在下面的评论中发布了该应用程序崩溃,请张贴崩溃日志,以便我们可以更好地了解发生了什么问题。 – 2012-07-23 12:02:59

回答

1

尝试使用选择

上设置doneButton dissmissmodalviewcontroller的行动
[doneButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 

在解雇法

-(void)dismiss 
    { 

    [self dismissmodalViewController]; 

    } 
+0

感谢您的帮助,但它不起作用。我在覆盖区域中实现了第一行代码。该应用程序实际上在启动时崩溃。让我们忘记规范,我将如何通过使用done按钮来终止UIImagePickerController会话? – 2012-07-23 06:28:15

+0

你在doneButtonTap方法中写了些什么 – 2012-07-23 06:40:08

相关问题