Search code examples
iosobjective-cios6uiimagepickercontroller

Non-modal UIImagePickerController, tap to focus doesn't work


I'm using a UIImagePickerController in a non-modal setting, like this:

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 tap on the preview area to make the camera focus on that point. I tried fixing this by adding one or both of these 2 lines:

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

but no luck. When I make it show the camera controls, I do get the flash mode button and the button to choose the camera, but those buttons are not tappable as well. Is it possible to make the tap to focus work in my situation?


Solution

  • I repeated your code and tap to focus and buttons works. (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];
    }
    

    Ensure that mainCameraPreviewContainer.userInteractionEnabled == YES.