0

this code for manual focus worked until a few days ago. Now it doesn't work... does anyone know why?

@IBAction func tap23(_ sender: UITapGestureRecognizer) {
    if (sender.state == .ended) {
        let thisFocusPoint = sender.location(in: photoImage)

        print("touch to focus ", thisFocusPoint)

        let focus_x = thisFocusPoint.x / view.frame.size.width
        let focus_y = thisFocusPoint.y / view.frame.size.height

        if (currentCamera!.isFocusModeSupported(.autoFocus) && currentCamera!.isFocusPointOfInterestSupported) {
            do {
                try currentCamera?.lockForConfiguration()
                currentCamera?.focusMode = .autoFocus
                currentCamera?.focusPointOfInterest = CGPoint(x: focus_x, y: focus_y)

                if (currentCamera!.isExposureModeSupported(.autoExpose) && currentCamera!.isExposurePointOfInterestSupported) {
                    currentCamera?.exposureMode = .autoExpose;
                    currentCamera?.exposurePointOfInterest = CGPoint(x: focus_x, y: focus_y);
                }

                currentCamera?.unlockForConfiguration()
            } catch {
                print(error)
            }
        }
    }
}

The preview Layer of my camera is an UIImageView. A few days ago it was UIView... please, anyone...This is my first iOs app

  • 1
    please describe what you face in this code? –  Apr 30 '18 at 09:02
  • Possible duplicate of [iOS tap to focus](https://stackoverflow.com/questions/28086096/ios-tap-to-focus) – HHK Apr 30 '18 at 13:53
  • Also, in the question I just linked, most answers use manual calculations to compute the point of focus. Don't. It is much better to rely on the method `captureDevicePointOfInterestForPoint` that is available on your `AVCaptureVideoPreviewLayer` – HHK Apr 30 '18 at 13:54

0 Answers0