ios - How to implement "pinch to zoom" in custom camera -
i have custom photo/video camera (think snapchat) pinch recognizer zoom in/out. here's what's going right based on code found online:
- zooming in works properly
- capturing image captures zoomed image
here's what's going wrong need with:
- zoom out causes crash
- although zooming in works, seems reset zoom if zoom in, stop touching screen, try zoom in again.
- capturing video resets zoom
this code pinch gesture, should changed?
for input in self.capturesession.inputs { // check input camera , not 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 _{ } } } }
you have set videozoomfactor based on former value.
do { try device.lockforconfiguration() switch gesture.state { case .began: self.pivotpinchscale = device.videozoomfactor case .changed: var factor = self.pivotpinchscale * gesture.scale factor = max(1, min(factor, device.activeformat.videomaxzoomfactor)) device.videozoomfactor = factor default: break } device.unlockforconfiguration() } catch { // handle exception } you should have saved former scale factor in order start zoom in/out current zoom state, self.pivotpinchscale in above example key. wish can hints following example.
Comments
Post a Comment