ios - 如何在IOS中检查自动对焦是否仍在进行?

标签 ios objective-c avcapturesession avcapturedevice avcapture

我现在创建了相机应用程序,我想做的是需要检查焦点是持续还是停止。

这就是我尝试过的:

 NSError *error=nil;
    //Capture Session
    AVCaptureSession *session = [[AVCaptureSession alloc]init];
    session.sessionPreset = AVCaptureSessionPresetPhoto;

    //Add device
    AVCaptureDevice *device =
    [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    // SETUP FOCUS MODE
    if ([device lockForConfiguration:nil]) {

        [device setFocusMode:AVCaptureFocusModeAutoFocus];

        [device unlockForConfiguration];
    }
    else{
        NSLog(@"error while configuring focusMode");
    }
    NSLog(@"%@" ,NSStringFromCGPoint(device.focusPointOfInterest));
    if ([device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus] && [device lockForConfiguration:&error]){
        [device setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
        if ([device isFocusPointOfInterestSupported])
            [device setFocusPointOfInterest:CGPointMake(0.5f,0.5f)];
        [device unlockForConfiguration];
    }
    else{
        NSLog(@"problem ");
    }

    //Input
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];

    if (!input)
    {
        NSLog(@"No Input");
    }

    [session addInput:input];

    //Preview Layer
    AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
    UIView *myView = viewForCamera;
    previewLayer.frame = myView.bounds;
    previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    [viewForCamera.layer addSublayer:previewLayer];

    //Start capture session
    [session startRunning];

我搜索了是否有任何委托(delegate)方法,但我没有得到,请帮我解决这个问题。

最佳答案

我得到了解决方案。我尝试了示例。我用谷歌搜索并经历了很多答案。

We must set the point of interest before calling setFocusMode



在您的编码中,您没有调用兴趣点
if ([device isFocusPointOfInterestSupported])
{
   [device setFocusPointOfInterest:CGPointMake(0.5f,0.5f)];
   [device setFocusMode:AVCaptureFocusModeAutoFocus];
             //OR
   [device setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
   [device unlockForConfiguration];
}

AutoFocus is not working

然后查找自动对焦是否进行

Auto Focus Observer

关于ios - 如何在IOS中检查自动对焦是否仍在进行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38865184/

相关文章:

ios - Mantle 和 CoreData 集成

iOS7 后台同步(使用 NSURLSessionDataTask?)

ios - 如何在带有约束 iOS 的单个 UIView 中设置 4 个具有相同间隙的 UIView

iphone - 在 iOS 中使用 AVCaptureMovieFileOutput 和 AVCaptureVideoDataOutput 暂停和恢复视频捕获

ios - AvCaptureSession代码提取错误

ios - 具有循环行为的 iPhone Storyboard

ios - AsyncDisplayKit错误(使用ASDK作为静态库)

ios - 制作自定义分段 Controller 的替代方法

ios - Objective-C - 改变控件的外观实现外观 api

android - 用于移动(Android/IOS)和 Web 应用程序的 VOIP 库