2

I am using ZBarSDK for scanning QR codes using an iPad. I have this successfully working currently. However, the code I have currently opens the camera in a fullscreen modal view controller but I want to embed the camera view inside of a UIView.

This is my code as it stands now, which works fine as a modal view controller. But I want to show the camera in a UIView I have created called "showCamera". I searched the net and these forums and there were some similar questions but didn't provide code in an answer.

ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.showsZBarControls = TRUE;
reader.cameraDevice=UIImagePickerControllerCameraDeviceFront;

reader.readerView.torchMode = 0;

ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 0];

// present and release the controller
[self presentModalViewController: reader animated: YES];

As I said earlier, the UIView I want to show the camera in is:

@property (strong, nonatomic) IBOutlet UIView *showCamera;

Thanks in advance!

Bobster4300
  • 254
  • 4
  • 15

1 Answers1

3

Until iOS 4 the camera would always open full screen. What you can do is overlay a part of that screen with your own view. You can do this by putting your view on top of it (with a transparent area):

reader.cameraOverlayView = myView;

Since iOS 4+ you can use the readerView. Since it is just a UIView you can use it like any other view. For instance:

readerView = [ZBarReaderView new]; readerView.frame = CGRectMake(...); // other view setup... [self.view addSubview: readerView];
BConic
  • 8,750
  • 2
  • 29
  • 55
Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58
  • Thank you. But I thought ZBar had a "reader View" (ZbarReaderView) that could be used for my purpose? Just struggling to find how to use it as ZBar's own documentation doesn't include how to do it and says "you're on your own". – Bobster4300 Dec 14 '12 at 09:18
  • Apperently since iOS 4+ you can use the readerView. Since it's just a UIView you can use it like any other view. for instance like this: readerView = [ZBarReaderView new]; readerView.frame = CGRectMake(...); // other view setup... [self.view addSubview: readerView]; – Edwin Vermeer Dec 14 '12 at 14:12
  • I managed to get the camera showing in a UIView now but get an error when it scans a code. I posted a new question about it. I'm happy to accept your answer Edwin if you make it a proper answer? – Bobster4300 Dec 16 '12 at 05:01