John Doe
John Doe

Reputation: 1609

Tap To Focus And Exposure Doesn't Work

I've been trying to do tap to focus for a while, and I've virtually tried everything but none of them seem to work for me. Below is what I have in my touchesBegan and it doesn't work. It should but it isn't. What am I doing wrong?

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

Upvotes: 0

Views: 322

Answers (1)

Katz
Katz

Reputation: 866

You made minor mistakes in your code, the lines below should fix it.

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

Upvotes: 1

Related Questions