非模态UIImagePickerController,点击焦点不起作用

时间:2013-03-02 20:05:31

标签: ios objective-c ios6 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;

但没有运气。当我让它显示相机控件时,我确实得到了闪光模式按钮和按钮来选择相机,但这些按钮也不是可以点击的。是否可以让水龙头专注于我的工作?

3 个答案:

答案 0 :(得分:2)

我重复你的代码,然后点击聚焦和按钮工作。 (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

答案 1 :(得分:1)

http://jcuz.wordpress.com/2010/02/17/pickerfocus/你可以尝试一下。

我建议你使用AVfoundation实现。它更容易,更灵活。 使用AVFoundation ios AVFoundation tap to focus

答案 2 :(得分: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);
         }
     }
}