Thanks for the answer MacN00b! This indicates the right direction for me. I implemented tap-focus for zbarViewController. Here is an idea:
You can add a custom view to zbarViewController by assigning a custom view to its CameraOverlayView. Then add the TapGestureRecagonizer to your custom view to catch the tap. Then get the touch point and make the camera focus tangent. You would like to add a small rectangle around the touch point (this is what I did).
Here comes the code (assigning a custom view for the OverlayView camera:
UIView *view = [[UIView alloc] init]; UITapGestureRecognizer* tapScanner = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(focusAtPoint:)]; [view addGestureRecognizer:tapScanner]; reader.cameraOverlayView = view;
Then in the focusAtPoint selector:
- (void)focusAtPoint:(id) sender{ CGPoint touchPoint = [(UITapGestureRecognizer*)sender locationInView:_reader.cameraOverlayView]; double focus_x = touchPoint.x/_reader.cameraOverlayView.frame.size.width; double focus_y = (touchPoint.y+66)/_reader.cameraOverlayView.frame.size.height; NSError *error; NSArray *devices = [AVCaptureDevice devices]; for (AVCaptureDevice *device in devices){ NSLog(@"Device name: %@", [device localizedName]); if ([device hasMediaType:AVMediaTypeVideo]) { if ([device position] == AVCaptureDevicePositionBack) { NSLog(@"Device position : back"); CGPoint point = CGPointMake(focus_y, 1-focus_x); if ([device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus] && [device lockForConfiguration:&error]){ [device setFocusPointOfInterest:point]; CGRect rect = CGRectMake(touchPoint.x-30, touchPoint.y-30, 60, 60); UIView *focusRect = [[UIView alloc] initWithFrame:rect]; focusRect.layer.borderColor = [UIColor whiteColor].CGColor; focusRect.layer.borderWidth = 2; focusRect.tag = 99; [_reader.cameraOverlayView addSubview:focusRect]; [NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @selector(dismissFocusRect) userInfo: nil repeats: NO]; [device setFocusMode:AVCaptureFocusModeAutoFocus]; [device unlockForConfiguration]; } } } } }
I added a white rectangle around the touch point, and then use the rejectFocusRect selector to reject this rectangle. Here is the code:
- (void) dismissFocusRect{ for (UIView *subView in _reader.cameraOverlayView.subviews) { if (subView.tag == 99) { [subView removeFromSuperview]; } } }
Hope this helps!
source share