Dyldo42
Dyldo42

Reputation: 2348

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

Upvotes: 6

Views: 7757

Answers (6)

shripad20
shripad20

Reputation: 858

Instead of using ZBarReaderViewController, try using ZBarReaderView. This worked for me and saved my lot of time. Hope it helps you.

ZBarReaderView*reader = [ZBarReaderView new];
ZBarImageScanner * scanner = [ZBarImageScanner new];
[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 0];
reader = [reader initWithImageScanner:scanner];
reader.readerDelegate = self;
reader.tracksSymbols = YES;
reader.frame = CGRectMake(20, 38, 283, 347);
reader.torchMode = 0;
dispatch_async(dispatch_get_main_queue(), ^{[reader start];});

[self.view addSubview:reader];

Upvotes: 7

Dejell
Dejell

Reputation: 14337

The best way to do it so it will be inside a sampleView :

UIView *view = [self sampleView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
CGRect bounds = [view bounds];
[reader.view.layer setFrame:bounds];
[viewLayer insertSublayer:reader.view.layer below:[[viewLayer sublayers] objectAtIndex:0]];

Upvotes: 0

Chirag Lukhi
Chirag Lukhi

Reputation: 1546

Try this It may help you:

ZBarReaderViewController *reader= [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;

ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here

//    reader.showsCameraControls = NO;  // for UIImagePickerController
reader.showsZBarControls = NO;

// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology:ZBAR_I25|ZBAR_QRCODE
               config: ZBAR_CFG_ENABLE
                   to: 0];
[reader viewDidLoad];
[reader viewWillAppear:NO];
[reader viewDidAppear:NO];

[self.viewScan addSubview:reader.view];

here,self.viewScan is any view of your current controller.

so scanning area now self.viewScan view.

Upvotes: 0

vedran
vedran

Reputation: 1153

another way to modify the properties of the scanning view controller is to import the ZBarSDK project and compile and link it yourself, rather than using the binary version of the SDK. Then, you can make any changes to the view controller that you need to (keep in mind their license...should probably read that first)

Upvotes: 0

Dyldo42
Dyldo42

Reputation: 2348

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.

Upvotes: 2

Luke
Luke

Reputation: 378

You can create your own view and view controller,and add the ZBarReaderViewController's view as a subview of your own view;

Upvotes: 0

Related Questions