简体   繁体   English

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

[英]Non-modal UIImagePickerController, tap to focus doesn't work

I'm using a UIImagePickerController in a non-modal setting, like this: 我在非模态设置中使用UIImagePickerController,如下所示:

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

This works, and I can take pictures, but I can't tap on the preview area to make the camera focus on that point. 这是有效的,我可以拍照,但我无法点击预览区域,使相机专注于该点。 I tried fixing this by adding one or both of these 2 lines: 我尝试通过添加以下两行中的一行或两行来修复此问题:

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

but no luck. 但没有运气。 When I make it show the camera controls, I do get the flash mode button and the button to choose the camera, but those buttons are not tappable as well. 当我让它显示相机控件时,我确实得到了闪光模式按钮和按钮来选择相机,但这些按钮也不是可以点击的。 Is it possible to make the tap to focus work in my situation? 是否有可能让水龙头专注于我的工作?

I repeated your code and tap to focus and buttons works. 我重复你的代码并点击聚焦和按钮工作。 (iOS 5.1, 6.1). (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];
}

Ensure that mainCameraPreviewContainer.userInteractionEnabled == YES . 确保mainCameraPreviewContainer.userInteractionEnabled == YES

http://jcuz.wordpress.com/2010/02/17/pickerfocus/ You can give this a try. http://jcuz.wordpress.com/2010/02/17/pickerfocus/你可以尝试一下。

I would suggest you to implement using AVfoundation. 我建议你使用AVfoundation实现。 Its more easy and more flexible. 它更容易,更灵活。 using AVFoundation ios AVFoundation tap to focus 使用AVFoundation ios AVFoundation点击聚焦

Try this and let me know.. 试试这个让我知道..

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM