Ios 非模态UIImagePickerController,轻触至焦点不';行不通

Ios 非模态UIImagePickerController,轻触至焦点不';行不通,ios,objective-c,ios6,uiimagepickercontroller,Ios,Objective C,Ios6,Uiimagepickercontroller,我在非模式设置中使用UIImagePickerController,如下所示: UIImagePickerController *_imagePickerVC = // init the VC with the main camera as the source [_mainCameraPreviewContainer addSubview:_imagePickerVC.view]; [_mainCameraPreviewContainer bringSubviewToFront:_imageP

我在非模式设置中使用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;
但是没有运气。当我让它显示相机控件时,我确实可以使用闪光灯模式按钮和选择相机的按钮,但这些按钮也不能点击。在我的情况下,有可能使“点击聚焦”功能正常工作吗?

您可以试试

我建议您使用AVfoundation实现。它更容易,更灵活。
使用AVFoundation,我重复了您的代码,点击聚焦按钮即可。(iOS 5.1、6.1)


请确保
mainCameraPreviewContainer.userInteractionEnabled==YES

尝试此操作并让我知道

_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);
         }
     }
}

就是这样,问题是
mainCameraPreviewContainer.userInteractionEnabled
。谢谢你,伙计!
_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);
         }
     }
}