LNS
LNS

Reputation: 43

ZBarReaderView with custom size from storyboard moving after start is called

i've got a ZBarReaderView created from storyboard with 216x20 px which is shown as roughly 230x50 px because ZBarReaderView doesn't take it's size too serious... It all works very well, however it behaves really strange when I call start on that readerView. It starts the cam but then in maybe half a second the readerView zooms a bit and the camera picture inside the readerView moves down and then up again. It's not terrible but it look kinda bad. Anyone got any ideas what might be causing this and how to solve it? Maybe the sdk has some sort of hidden callback for the readiness of the scanner, i could hide it until the scanner says it's ready and then show the scanner like .5 seconds later...

barcodeReader is the iboutlet to the ZBarReaderView and scannerLoading is an iboutlet to a uiactivityindicatorview which is animating until the scanner is loaded. These are the only settings which are changed from default, except the frame which is set in the storyboard of course.

[barcodeReader setReaderDelegate:self];
[barcodeReader setAllowsPinchZoom:false];
[barcodeReader start];

/* this works because [barcodeReader start] blocks ui updates until the scanner
   is running, i know it's not a good solution but since there doesn't seem to 
   be a callback or delegate method like scannerDidStart or something it seems 
   to be the only way... */
[scannerLoading stopAnimating]; 

Thanks for your help!

Upvotes: 3

Views: 2178

Answers (2)

butters
butters

Reputation: 164

I just posted an answer to a retaliated question:

ZBarReadview with custom size from StoryBoard,but when it's called,it's size is not I set

Maybe the answer also solves your problem.

In short:

When using Interface Builder or Storyboard to create a view and assign the ZBarReaderView to it, you have to check "Clip Subviews" in the properties for the camera image to keep the size of the view.

Upvotes: 3

hacker
hacker

Reputation: 8957

Just add another view to make it as cameraoverlayview with an image view having the image which is having required part of it as transparent.then in the button action `

// ADD: present a barcode reader that scans from the camera feed

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

reader.supportedOrientationsMask = ZBarOrientationMaskAll;

reader.sourceType=UIImagePickerControllerSourceTypeCamera;
//reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;

reader.cameraOverlayView=cameraOverlay;

if( [UIImagePickerController isCameraDeviceAvailable:                         UIImagePickerControllerCameraDeviceFront ])
{
       reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
ZBarImageScanner *scanner = reader.scanner;

reader.wantsFullScreenLayout = YES;
// TODO: (optional) additional reader configuration here

// EXAMPLE: disable rarely used I2/5 to improve performance

[scanner setSymbology: ZBAR_I25
               config: ZBAR_CFG_ENABLE
                   to: 0];
 reader.showsZBarControls = NO; 
// present and release the controller

[self presentModalViewController:reader animated:YES]; //[appdel.navigationController pushViewController:reader animated:YES];

//[reader.view addSubview:collect];


[reader release];add this and then also add 

`- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info { // ADD: get the decode results id results = [info objectForKey: ZBarReaderControllerResults]; ZBarSymbol *symbol = nil; for(symbol in results) // EXAMPLE: just grab the first barcode break;

 [self rewards:symbol.data];

} `

as a method .hope this will solve your issue

Upvotes: 0

Related Questions