【问题标题】:Non-modal UIImagePickerController, tap to focus doesn't work非模态 UIImagePickerController,点击聚焦不起作用
【发布时间】:2013-02-17 04:49:54
【问题描述】:

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

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

【问题讨论】:

    标签: ios objective-c ios6 uiimagepickercontroller


    【解决方案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];
    }
    

    确保mainCameraPreviewContainer.userInteractionEnabled == YES

    【讨论】:

    • 就是这样,问题是mainCameraPreviewContainer.userInteractionEnabled。谢谢大佬!
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      试试这个,让我知道..

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

      【讨论】:

        猜你喜欢
        • 2016-06-15
        • 2012-04-27
        • 1970-01-01
        • 2020-11-18
        • 2011-12-29
        • 2012-11-02
        • 2017-02-06
        • 1970-01-01
        相关资源
        最近更新 更多