diff --git a/ios/CsZBar.m b/ios/CsZBar.m index 6c4bd6a..122a1b0 100644 --- a/ios/CsZBar.m +++ b/ios/CsZBar.m @@ -8,6 +8,7 @@ @interface CsZBar () @property bool scanInProgress; @property NSString *scanCallbackId; @property AlmaZBarReaderViewController *scanReader; +@property (strong, nonatomic) UITapGestureRecognizer *tapOutsideRecognizer; @end @@ -100,7 +101,7 @@ - (void)scan: (CDVInvokedUrlCommand*)command; self.scanReader.cameraOverlayView = polygonView; } - + [self.viewController.view.window addGestureRecognizer:self.tapBehindGesture]; [self.viewController presentViewController:self.scanReader animated:YES completion:nil]; } } @@ -170,4 +171,27 @@ - (void) readerControllerDidFailToRead:(ZBarReaderController*)reader withRetry:( }]; } +- (UITapGestureRecognizer*)tapBehindGesture +{ + if (_tapOutsideRecognizer == nil) + { + _tapOutsideRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBehindRecognized)]; + _tapOutsideRecognizer.numberOfTapsRequired = 1; + _tapOutsideRecognizer.cancelsTouchesInView = NO; + _tapOutsideRecognizer.delegate = self; + } + + return _tapOutsideRecognizer; +} + +-(void)tapBehindRecognized { + [self.viewController.view.window removeGestureRecognizer:self.tapBehindGesture]; + self.scanInProgress = NO; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer +{ + return YES; +} + @end