我正在使用录像机应用程序,我想以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
}
}
//}
}
请帮助。!