非模态UIImagePickerController,点击对焦无法工作。

4

我正在非模态设置中使用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;

但是没有运气。当我让它显示相机控件时,我确实会得到闪光模式按钮和选择相机的按钮,但这些按钮也无法点击。在我的情况下,是否有可能使触摸对焦功能正常工作?

3个回答

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

那就是了,问题出在 mainCameraPreviewContainer.userInteractionEnabled。谢谢! - TotoroTotoro

1
试一下这个,然后让我知道。
_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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接