I have a custom photo/video camera (think Snapchat) with a pinch recognizer to zoom in/out. Here's what's going right based on some code I found online:
- Zooming in somewhat works properly
- Capturing an image captures the zoomed image
Here's what's going wrong that I need help with:
- Zoom out causes crash
- Although zooming in works, it seems to reset the zoom if I zoom in, stop touching the screen, then try to zoom in again.
- Capturing video resets the zoom
This is my code for the pinch gesture, what should be changed?
for input in self.captureSession.inputs {
// check that the input is a camera and not the audio
if input.device == self.frontCameraDevice || input.device == self.backCameraDevice {
if pinch.state == UIGestureRecognizerState.Changed {
let device: AVCaptureDevice = input.device
let vZoomFactor = pinch.scale
do{
try device.lockForConfiguration()
if vZoomFactor <= device.activeFormat.videoMaxZoomFactor {
device.videoZoomFactor = vZoomFactor
device.unlockForConfiguration()
}
}catch _{
}
}
}
}