How Do I Change The Frame Of A ZBar Reader?
Asked Answered
A

6

6

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];
Anaesthesiology answered 6/7, 2011 at 23:23 Comment(3)
I am working on barcode reader app which reads barcode and display its data using zbar Sdk. Now client wants to customize the square bracket which appears when camera auto focus the barcode. How to customize it like this??? i.sstatic.net/NkKQr.png ThanksExcelsior
What does listTableView resolve to? Is this a custom view you instantiated somewhere else? Also is overlayView an iVar?Vorfeld
You are posting code which doesn't work. Can you please answer above comment?Kumler
A
2

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.

Anaesthesiology answered 11/7, 2011 at 1:55 Comment(3)
How did you reset the frame? Adding as a subview seems to provide a blank black screen.Anagnorisis
Is your code similar to mine above? If not, try it and tell me how you go.Anaesthesiology
@Anaesthesiology Can you put the Code Here?Biosynthesis
F
7

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];
Flabellum answered 13/3, 2014 at 11:22 Comment(0)
A
2

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.

Anaesthesiology answered 11/7, 2011 at 1:55 Comment(3)
How did you reset the frame? Adding as a subview seems to provide a blank black screen.Anagnorisis
Is your code similar to mine above? If not, try it and tell me how you go.Anaesthesiology
@Anaesthesiology Can you put the Code Here?Biosynthesis
T
0

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

Trampoline answered 7/7, 2011 at 7:24 Comment(2)
It's not as simple as that. See my answer above.Anaesthesiology
ZBarReaderViewController is a ViewController, not a UIView. So, you can't add simply as a subview!Experimentalize
M
0

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)

Microorganism answered 10/6, 2012 at 2:59 Comment(0)
V
0

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.

Vc answered 2/1, 2013 at 7:12 Comment(1)
But only one issue, barcode not scanner not detect and not called delegate method.Leahleahey
K
0

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]];
Kumler answered 20/3, 2013 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.