diff --git a/ios/CsZBar.m b/ios/CsZBar.m index 45a15ab..8f1c2c3 100644 --- a/ios/CsZBar.m +++ b/ios/CsZBar.m @@ -35,7 +35,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface #pragma mark - Plugin API -- (void)scan: (CDVInvokedUrlCommand*)command; +- (void)scan: (CDVInvokedUrlCommand*)command; { if (self.scanInProgress) { [self.commandDelegate @@ -62,7 +62,7 @@ - (void)scan: (CDVInvokedUrlCommand*)command; self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn; NSString *flash = [params objectForKey:@"flash"]; - + if ([flash isEqualToString:@"on"]) { self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn; } else if ([flash isEqualToString:@"off"]) { @@ -85,24 +85,27 @@ - (void)scan: (CDVInvokedUrlCommand*)command; CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenRect.size.width; CGFloat screenHeight = screenRect.size.height; - + BOOL drawSight = [params objectForKey:@"drawSight"] ? [[params objectForKey:@"drawSight"] boolValue] : true; UIToolbar *toolbarViewFlash = [[UIToolbar alloc] init]; - + //The bar length it depends on the orientation toolbarViewFlash.frame = CGRectMake(0.0, 0, (screenWidth > screenHeight ?screenWidth:screenHeight), 44.0); toolbarViewFlash.barStyle = UIBarStyleBlackOpaque; UIBarButtonItem *buttonFlash = [[UIBarButtonItem alloc] initWithTitle:@"Flash" style:UIBarButtonItemStyleDone target:self action:@selector(toggleflash)]; - + NSArray *buttons = [NSArray arrayWithObjects: buttonFlash, nil]; [toolbarViewFlash setItems:buttons animated:NO]; [self.scanReader.view addSubview:toolbarViewFlash]; if (drawSight) { CGFloat dim = screenWidth < screenHeight ? screenWidth / 1.1 : screenHeight / 1.1; - UIView *polygonView = [[UIView alloc] initWithFrame: CGRectMake ( (screenWidth/2) - (dim/2), (screenHeight/2) - (dim/2), dim, dim)]; - - UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,dim / 2, dim, 1)]; + UIView *polygonView = [[UIView alloc] initWithFrame: CGRectMake ( (screenWidth/2) - (dim/2), (screenHeight/2) - (dim/2), dim, dim)]; + //polygonView.center = self.scanReader.view.center; + polygonView.layer.borderColor = [UIColor whiteColor].CGColor; + polygonView.layer.borderWidth = 3.0f; + + UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, dim / 2, dim, 1)]; lineView.backgroundColor = [UIColor redColor]; [polygonView addSubview:lineView]; @@ -115,7 +118,7 @@ - (void)scan: (CDVInvokedUrlCommand*)command; - (void)toggleflash { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; - + [device lockForConfiguration:nil]; if (device.torchAvailable == 1) { if (device.torchMode == 0) { @@ -126,7 +129,7 @@ - (void)toggleflash { [device setFlashMode:AVCaptureFlashModeOff]; } } - + [device unlockForConfiguration]; } @@ -146,9 +149,9 @@ - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingM if ([self.scanReader isBeingDismissed]) { return; } - + id results = [info objectForKey: ZBarReaderControllerResults]; - + ZBarSymbol *symbol = nil; for (symbol in results) break; // get the first result