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;

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

4

3 回答 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.

于 2013-03-13T18:56:43.847 回答
1

http://jcuz.wordpress.com/2010/02/17/pickerfocus/你可以试试这个。

我建议你使用 AVfoundation 来实现。它更容易,更灵活。使用 AVFoundation ios AVFoundation 点击​​聚焦

于 2013-03-10T13:59:00.773 回答
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);
         }
     }
}
于 2013-03-15T05:28:22.467 回答