首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ios 9 AVCaptureDevice设置焦点

ios 9 AVCaptureDevice设置焦点
EN

Stack Overflow用户
提问于 2016-04-18 14:19:27
回答 1查看 1.9K关注 0票数 2

我正试着用前面的摄像机设定焦点。

代码语言:javascript
复制
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    let screenSize = cameraView.bounds.size

    let frameSize:CGSize = view.frame.size

    if let touchPoint = touches.first {

        var location:CGPoint = touchPoint.locationInView(cameraView)

        print("Tap Location : X: \(location.x), Y: \(location.y)")

        if cameraManager.cameraDevice == .Front {
            print("Front camera is used")

            location.x = frameSize.width - location.x;
        }
        else {
            print("Back camera is used")
        }

        let x = location.x / frameSize.width
        let y = 1.0 - (location.x / frameSize.width)

        let focusPoint = CGPoint(x: x, y: y)

        print("POINT : X: \(x), Y: \(y)")


        let captureDevice = (AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) as! [AVCaptureDevice]).filter{$0.position == .Front}.first

        if let device = captureDevice {
            do {
                try device.lockForConfiguration()

                let support:Bool = device.focusPointOfInterestSupported

                if support  {

                    print("focusPointOfInterestSupported: \(support)")

                    device.focusPointOfInterest = focusPoint

                    // device.focusMode = .ContinuousAutoFocus
                    device.focusMode = .AutoFocus
                    // device.focusMode = .Locked

                    device.unlockForConfiguration()

                    print("Focus point was set successfully")
                }
                else{
                    print("focusPointOfInterestSupported is not supported: \(support)")
                }
            }
            catch {
                // just ignore
                print("Focus point error")
            }
        }
    }
}

它适用于iphone6上的后摄像头.但是,当我激活前面的摄像机,它打了。focusPointOfInterestSupported总是返回false。

我怎样才能解决这个问题。我可以以编程方式设置焦点吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-18 16:19:37

focusPointOfInterestSupported布尔值表示此设备的前置摄像机不支持以这种方式设置焦点。事实上,看起来iPhone 6的“iPhone”相机有一个固定的焦点。在iPhone 6 "FaceTime“相机的技术规格部分中没有提到”焦点“,但是在后面的"iSight”摄像头部分。此外,试图在靠近镜头的模糊物体上重新对焦(通过在相机应用程序中点击)似乎只是调整曝光,而不是对焦。

来源:ref/occ/instp/AVCaptureDevice/focusPointOfInterestSupported

来源:http://www.apple.com/iphone-6/specs/

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36696648

复制
相关文章

相似问题

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