简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM