如何使用自定义按钮从UImagePickerController中解除视图?

时间:2012-07-23 05:30:24

标签: iphone button uiimagepickercontroller terminate

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

这是我设置完成按钮的叠加层。

-(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];
}

1 个答案:

答案 0 :(得分:1)

尝试使用selector

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

解雇方法

 -(void)dismiss
    {

    [self dismissmodalViewController];

    }