我一直在尝试点一下焦点,实际上我已经尝试了所有方法,但似乎没有一种适合我。以下是我接触到的内容,它不起作用。应该,但不是。我究竟做错了什么?

var newFocusPoint = CGPoint(x: touchPoint.locationInView(cameraView).x / screenSize.width, y: touchPoint.locationInView(cameraView).y / screenSize.height)

    if let cameraDevice = device {
        if(cameraDevice.lockForConfiguration(nil)) {
            if cameraDevice.focusPointOfInterestSupported {
                cameraDevice.focusPointOfInterest = newFocusPoint
                cameraDevice.focusMode = AVCaptureFocusMode.ContinuousAutoFocus
            }
            if cameraDevice.exposurePointOfInterestSupported {
                cameraDevice.exposurePointOfInterest = newFocusPoint
                cameraDevice.exposureMode = AVCaptureExposureMode.ContinuousAutoExposure
            }
            cameraDevice.unlockForConfiguration()
        }
    }

最佳答案

您在代码中犯了一些小错误,下面的几行应予以解决。


 cameraDevice.focusPointOfInterest = focusPoint
 cameraDevice.focusMode = AVCaptureFocusMode.AutoFocus
 cameraDevice.exposurePointOfInterest = focusPoint
 cameraDevice.exposureMode = AVCaptureExposureMode.ContinuousAutoExposure

关于ios - 点击以聚焦和曝光不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33092496/

10-09 16:29