点击聚焦和曝光不起作用

时间:2015-10-13 00:55:21

标签: ios iphone swift camera avfoundation

我一直试图专注于关注一段时间,而我几乎尝试过所有事情,但它们似乎都不适合我。以下是我在touchesBegan中所拥有的内容并且它不起作用。它应该但不是。我究竟做错了什么?

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()
        }
    }

1 个答案:

答案 0 :(得分:1)

  

您在代码中犯了一些小错误,下面的行应该修复它。

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