如何使用像 TikTok App 这样的平移手势来缩放相机

How to Zoom camera using pan gesture like TikTok App

我正在开发录像机应用程序,我想要像 Titok 一样的功能,例如在平移手势上他们正在缩放相机我使用了以下代码但使用此代码我可以通过拖动进行缩放这是不可行的我想继续缩放放大和缩小。

@objc func previewPan(recognizer:UIPanGestureRecognizer) {
        viewShoot.isHidden = false
        //DispatchQueue.main.async {


        if recognizer.state == UIGestureRecognizerState.began {

            //self.StartRecording()

            //self.startPoint = recognizer.location(in: self.viewShoot)
            startPoint = recognizer.location(in: self.viewAnimate)

            self.zoomAtStart = self.recorder.videoZoomFactor

        } else if recognizer.state == UIGestureRecognizerState.changed {

            //let newPoint = recognizer.location(in: self.viewShoot)
            let newPoint = recognizer.location(in: self.viewAnimate)

            let scale = self.startPoint.y / newPoint.y
            var newZoom = scale * self.zoomAtStart

            if newZoom > self.maxZoomFactor {
                newZoom = self.maxZoomFactor
            } else if newZoom < self.minZoomFactor {
                newZoom = self.minZoomFactor
            }
            self.recorder.videoZoomFactor = newZoom

            //------->
            //self.viewShoot.isHidden = false
            //self.viewAnimate.isHidden = false

            //self.view.bringSubview(toFront: self.viewShoot)
            self.view.bringSubview(toFront: self.viewAnimate)

            let translation = recognizer.translation(in: self.view)

            //self.viewShoot.center = CGPoint(x: self.viewShoot.center.x + translation.x, y: self.viewShoot.center.y + translation.y)
            self.viewAnimate.center = CGPoint(x: self.viewAnimate.center.x + translation.x, y: self.viewAnimate.center.y + translation.y)


            recognizer.setTranslation(CGPoint.zero, in: self.view)

        } else if recognizer.state == UIGestureRecognizerState.ended {

            //self.StopRecording()

            UIView.animate(withDuration: 0.250) {
                //self.viewShoot.frame = self.originalPossion
                self.viewAnimate.frame = self.originalPossion
            }
        }
        //}
    }

请帮忙!

我已经使用 NextLevelZoom

解决了这个问题