2

I'm using SwiftyCam as CustomCamera in my App. but in camera i notice focus sometime not changing. if i tap on far object it not going focus fast and sometime i need to move my phone. I'm not able to find reason why this happening. Below is the code snippet for when user tap on screen. I also attached the image for comparison. First two image is capture from the custom camera and last two from Apple default camera.Image

@objc fileprivate func singleTapGesture(tap: UITapGestureRecognizer) {
    guard tapToFocus == true else {
        // Ignore taps
        return
    }

    let screenSize = previewLayer!.bounds.size
    let tapPoint = tap.location(in: previewLayer!)
    let x = tapPoint.y / screenSize.height
    let y = 1.0 - tapPoint.x / screenSize.width
    let focusPoint = CGPoint(x: x, y: y)

    if let device = videoDevice {
        do {
            try device.lockForConfiguration()

            if device.isFocusPointOfInterestSupported == true {
                device.focusPointOfInterest = focusPoint
                device.focusMode = .autoFocus
            }
            device.exposurePointOfInterest = focusPoint
            device.exposureMode = AVCaptureDevice.ExposureMode.continuousAutoExposure
            device.unlockForConfiguration()
            if exposureSlider != nil {
                exposureSlider.setValue(device.iso, animated: true)
            }
            //Call delegate function and pass in the location of the touch
            DispatchQueue.main.async {
                self.cameraDelegate?.swiftyCam(self, didFocusAtPoint: tapPoint)
                // add it manually show the slider and change value if there is no touch then remove it after some time
                if self.isexposureSliderHidden == true {
                    self.addSlider()
                }else{
                    self.removeSlider()
                }

            }
        }
        catch {
            // just ignore
        }
    }

}
jay patel
  • 238
  • 2
  • 14

0 Answers0