Reputation: 1609
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
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