I\'m trying to make a pinch to zoom camera but I\'m encountering two problems. First is that it allows the user to zoom way too much in and way to much out, secondly when I take
var device: AVCaptureDevice = self.backCamera
var vZoomFactor = sender.scale
var error:NSError!
do{
try device.lockForConfiguration()
defer {device.unlockForConfiguration()}
if (vZoomFactor <= device.activeFormat.videoMaxZoomFactor) {
let desiredZoomFactor:CGFloat = vZoomFactor + atan2(sender.velocity, 5.0);
device.videoZoomFactor = max(1.0, min(desiredZoomFactor, device.activeFormat.videoMaxZoomFactor));
}
else {
NSLog("Unable to set videoZoom: (max %f, asked %f)", device.activeFormat.videoMaxZoomFactor, vZoomFactor);
}
}
catch error as NSError{
NSLog("Unable to set videoZoom: %@", error.localizedDescription);
}
catch _{
}