Modeless UIImagePickerController, click to focus does not work

I use UIImagePickerController in a non-modal setup, for example:

UIImagePickerController *_imagePickerVC = // init the VC with the main camera as the source [_mainCameraPreviewContainer addSubview:_imagePickerVC.view]; [_mainCameraPreviewContainer bringSubviewToFront:_imagePickerVC.view]; 

This works, and I can take pictures, but I can’t click on the preview area to focus the camera on that spot. I tried to fix this by adding one or both of these two lines:

 _imagePickerVC.showsCameraControls = NO; _imagePickerVC.view.userInteractionEnabled = YES; 

but no luck. When I show the camera controls, I have a flash mode button and a camera select button, but these buttons also cannot be displayed. Is it possible to press to focus the work in my situation?

+4
source share
3 answers

I repeated your code and pressed to focus and the buttons work. (iOS 5.1, 6.1).

 - (IBAction)buttonTap:(id)sender { if (!_imagePickerVC) { _imagePickerVC = [UIImagePickerController new]; _imagePickerVC.sourceType = UIImagePickerControllerSourceTypeCamera; } [self.view addSubview:_imagePickerVC.view]; [self.view bringSubviewToFront:_imagePickerVC.view]; } 

Make sure mainCameraPreviewContainer.userInteractionEnabled == YES .

+2
source

http://jcuz.wordpress.com/2010/02/17/pickerfocus/ You can try it.

I suggest you implement using AVfoundation. It is more easy and flexible. using AVFoundation ios AVFoundation click to focus

+1
source

Try this and let me know ..

 _imagePickerVC.view.userInteractionEnabled = YES; UIPanGestureRecognizer *pgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; [_imagePickerVC addGestureRecognizer:pgr]; [pgr release]; -(void)handleTap{ AVCaptureDevice *device = [[self captureInput] device]; NSError *error; if ([device isFocusModeSupported:AVCaptureFocusModeAutoFocus] && [device isFocusPointOfInterestSupported]) { if ([device lockForConfiguration:&error]) { [device setFocusPointOfInterest:point]; CGPoint point = [touch locationInView:self.cameraView]; point.x /= self.cameraView.frame.size.width; point.y /= self.cameraView.frame.size.height; [self focusAtPoint:point]; [device unlockForConfiguration]; } else { NSLog(@"Error: %@", error); } } } 
+1
source

All Articles