Reputation: 2348
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
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
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
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
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
Reputation: 2348
I worked it out. This is what I had to do:
This was very difficult and unintuitive and broke many of Apple's code design guidelines but, in the end, is still doable.
Upvotes: 2
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