我已经实现了以下代码来获得正常工作的缩放因子
var maxZoomScale = CGFloat.greatestFiniteMagnitude
var beginZoomScale = CGFloat(1.0)
var zoomScale = CGFloat(1.0)
fileprivate func zoomGesture(pinch: UIPinchGestureRecognizer) {
guard pinchToZoom == true && self.currentCamera == .rear else {
//ignore pinch
return
}
do {
let captureDevice = AVCaptureDevice.devices().first
try captureDevice?.lockForConfiguration()
zoomScale = min(maxZoomScale, max(1.0, min(beginZoomScale * pinch.scale, captureDevice!.activeFormat.videoMaxZoomFactor)))
captureDevice?.videoZoomFactor = zoomScale
// Call Delegate function with current zoom scale
DispatchQueue.main.async {
print("zoomScale : \(self.zoomScale)")
self.cameraDelegate?.swiftyCam(self, didChangeZoomLevel: self.zoomScale)
}
captureDevice?.unlockForConfiguration()
} catch {
print("Error locking configuration")
}
}
现在var zoomScale
给了我最大缩放因子1.011的缩放因子,现在我已达到1.98。
我需要X-time ,如1x,2x,3x ....
那我该怎么办呢?