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 a picture it doesn't take it of the zoomed in view. Here is my code for the pinch function...
func pinch(pinch: UIPinchGestureRecognizer) {
if let view = cameraView {
view.transform = CGAffineTransformScale(view.transform,
pinch.scale, pinch.scale)
pinch.scale = 1
}
}
Tell me if you need to see any more code. Thanks!
To expand on Ritvik Upadhyaya's answer, you would also need to save the previous zoom factor to calculate the new one, you wouldn't want the zooming to reset to normal every time you lift up your fingers and try zooming again.
I have experienced the same issues with the camera implementation. To solve this you need to know about two things.
AVCaptureDevice
's zoom.To change the two things you need something like this:
As you can see I use a class variable for the video device (
videoDevice
) to keep track of the capture device I am using for visual component. I restrict the zoom to a particular range and change the zoom property on the device and not the view itself!If you need a manual zoomTo(2.0) function, you can use this
Swift 3.0