Немодальный UIImagePickerController, нажмите, чтобы сфокусироваться, не работает

Я использую UIImagePickerController в немодальной настройке, например:

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

Это работает, и я могу делать снимки, но я не могу нажать на область предварительного просмотра, чтобы сфокусировать камеру на этой точке. Я попытался исправить это, добавив одну или обе эти строки:

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

но не повезло. Когда я заставляю его отображать элементы управления камерой, я получаю кнопку режима вспышки и кнопку выбора камеры, но эти кнопки также не нажимаются. Можно ли заставить работать тап для фокусировки в моей ситуации?


person TotoroTotoro    schedule 02.03.2013    source источник


Ответы (3)


Я повторил ваш код и нажмите, чтобы сфокусироваться, и кнопки работают. (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];
}

Убедитесь, что mainCameraPreviewContainer.userInteractionEnabled == YES.

person Sergey Kuryanov    schedule 13.03.2013
comment
Вот и все, проблема была mainCameraPreviewContainer.userInteractionEnabled. Спасибо чувак! - person TotoroTotoro; 16.03.2013

http://jcuz.wordpress.com/2010/02/17/pickerfocus/ Вы можете попробовать.

Я бы предложил вам реализовать с помощью AVfoundation. Это проще и гибче. с помощью AVFoundation коснитесь AVFoundation iOS, чтобы сфокусироваться

person Pushpak Narasimhan    schedule 10.03.2013

Попробуйте это и дайте мне знать ..

_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);
         }
     }
}
person Arun    schedule 15.03.2013