iphoneiosobjective-cbarcode-scannerzbar-sdk

How Do I Change The Frame Of A ZBar Reader?


Ok, so I'm using the ZBar SDK to scan barcodes in my iPhone app. I've successfully implemented the sample code, but now I want to change the frame of the scanner view (i.e: To half the screen size). I've tried setting the frame of the reader's view in viewDidLoad, but it resizes itself. I know this is going to be one of those really simple things I just missed, but any help would be much appreciated. Cheers.

EDIT: I got it to work. Here's my code:

ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
[reader setShowsZBarControls:NO];
[reader.readerView setScanCrop:(CGRect){ { 0, 0 }, { 0.43, 1 } }];
[reader.readerView start];
[self.view addSubview:reader.view];

overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[listTableView setFrame:CGRectMake(0, 208, 320, 208)];
[overlayView addSubview:listTableView];
[self.view addSubview:overlayView];

Solution

  • I worked it out. This is what I had to do:

    1. Add ZBarReaderViewController's view as subview of my own view (which annoyingly fills the entire view no matter what its frame is).
    2. Change scan size of ZBarReaderViewController to whatever size I want it to be (BEWARE: Setting this frame is not like setting one normally, just ask if you need help).
    3. Add any views that you want visible to the ZBarReaderViewController's overlay view.

    This was very difficult and unintuitive and broke many of Apple's code design guidelines but, in the end, is still doable.