首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >相机不聚焦于iPhone 4,运行iOS 7.1

相机不聚焦于iPhone 4,运行iOS 7.1
EN

Stack Overflow用户
提问于 2014-04-08 17:05:44
回答 4查看 1K关注 0票数 1

在iOS升级从7.0.6升级到7.1.0之后,我们遇到了麻烦。我没有在iPhone 4s,5,5c上看到这个问题,也没有看到运行iOS 7.1的5s对所有非碎片化的讨论都有这么多的问题。我正在张贴相机初始化代码:

代码语言:javascript
复制
- (void)initCapture
{
    //Setting up the AVCaptureDevice (camera)
    AVCaptureDevice* inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    NSError* cameraError;
    if ([inputDevice lockForConfiguration:&cameraError])
    {
        if ([inputDevice isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus])
        {
            NSLog(@"AVCaptureDevice is set to video with continuous auto focus");
            CGPoint autofocusPoint = CGPointMake(0.5f, 0.5f);
            [inputDevice setFocusPointOfInterest:autofocusPoint];
            [inputDevice setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
        }

        [inputDevice unlockForConfiguration];
    }

    //setting up the input streams
    AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:nil];

    //setting up up the AVCaptureVideoDataOutput
    AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
    captureOutput.alwaysDiscardsLateVideoFrames = YES;
    [captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];

    //setting up video settings
    NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
    NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
    NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];

    //passing the settings to the AVCaptureVideoDataOutput
[captureOutput setVideoSettings:videoSettings];

    //setting up the AVCaptureSession
    captureSession = [[AVCaptureSession alloc] init];
    captureSession.sessionPreset = AVCaptureSessionPresetMedium;

    [captureSession addInput:captureInput];
    [captureSession addOutput:captureOutput];

    if (!prevLayer)
{
        prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
    }
    NSLog(@"initCapture preview Layer %p %@", self.prevLayer, self.prevLayer);
    self.prevLayer.frame = self.view.bounds;
    self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    [self.view.layer addSublayer: self.prevLayer];

    [self.captureSession startRunning];
}

任何帮助都将不胜感激.

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-04-10 20:39:05

为了关闭这个线程,除了libzxing之外,我们还使用相机扫描QR代码。我们决定实现本机iOS 7.0 AVCaptureMetadataOutputObjectsDelegate,而不是旧的AVCaptureVideoDataOutputSampleBufferDelegate。元数据委托更简单、更简洁,我们发现http://nshipster.com/ios7/中的示例非常有用。

票数 1
EN

Stack Overflow用户

发布于 2014-04-08 17:14:17

你正在使用的苹果公司提供的代码已经过时了--他们现在已经完全重写了。我会试试运气,开始新的工作流程。

看看这里

票数 1
EN

Stack Overflow用户

发布于 2014-04-08 19:11:49

以下是诊断您的问题的一些想法:

  • 对于if ([inputDevice lockForConfiguration:&cameraError]),您没有其他的理由。再加一个。
  • 在其他情况下,记录cameraError中包含的错误。
  • 对于if ([inputDevice isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]),您没有其他的理由。添加一个;记录它,或者在那里添加一个断点,以便在调试中进行测试。
  • 在尝试使用focusPointOfInterestSupported之前,不要检查属性setFocusPointOfInterest的返回值。考虑在setFocusMode之前调用setFocusPointOfInterest (不确定这是否重要,但这就是我所拥有的)
  • 通常,在试图锁定配置之前,您可能需要执行所有检查。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22943718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档