How to use camera zoom feature (iOS)

! Important. Please keep in mind that the zoom is not meant to be dynamic. Its only mean to switch from 1 zoom state to another with a 'jump'. Any smooth zoom effects using the method below are impossible.

 

To call the camera zoom feature in Face AR SDK use the method 

_ = sdkManager.input.setZoomFactor(1.0)

The following code snippets show how to apply this method with UIKit elements. 

  • UISlider
@IBAction func zoomCamera(_ sender: UISlider) {
        _ = sdkManager.input.setZoomFactor(sender.value)
  }
  • UIGestureRecognizer
var zoomRecognizer: UIPinchGestureRecognizer!

zoomRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(setupZoom(sender:)))

effectView.addGestureRecognizer(zoomRecognizer)


@objc func setupZoom(sender: UIPinchGestureRecognizer) {

        struct Defaults {

            static let maxZoom: Float = 6.0

            static let minZoom: Float = 1.0

        }

       
        let scaledValue = Float(sender.scale)

        sender.scale = 1.0

        var zoom: Float = sdkManager.input.zoomFactor

        zoom = zoom * scaledValue

        zoom = min(Defaults.maxZoom, max(zoom, Defaults.minZoom))

        _ = sdkManager.input.setZoomFactor(zoom)

    }