How to change the frame of the ZBar reader?

Ok, so I use the ZBar SDK to scan barcodes in my iPhone app. I have successfully completed the code sample, but now I want to change the frame of the scanner view (i.e., half the size of the screen). I tried to set the reader view frame to viewDidLoad, but it resized. I know that this will be one of those very simple things that I just missed, but any help would be greatly appreciated. Greetings.

EDITOR: I have earned. Here is 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]; 
+6
source share
6 answers

I did it. This is what I had to do:

  • Add the ZBarReaderViewController view as a view of my own view (which annoyingly fills the whole view no matter what its frame is).
  • Change the scan size of the ZBarReaderViewController to whatever size I want (BEWARE: setting this frame is not like normal setting, just ask if you need help).
  • Add all the views you want to see as a ZBarReaderViewController overlay.

It was very complicated and unintuitive, and many of Apple's principles developed the code design, but, in the end, are still doable.

+2
source

Instead of using ZBarReaderViewController, try using ZBarReaderView. It worked for me and saved a lot of time. Hope this 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]; 
+7
source

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

0
source

Another way to change the properties of the scan view controller is to import the ZBarSDK project and compile and link to it yourself, rather than using the binary version of the SDK. Then you can make any changes to the view controller that you need (remember that their license ... probably should be read first)

0
source

Try this. It can 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.

now the scan area is now self.viewScan .

0
source

The best way to do this is to have it inside 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]]; 
0
source

Source: https://habr.com/ru/post/892185/


All Articles