Pinch to zoom camera

后端 未结 6 1492
再見小時候
再見小時候 2021-02-07 13:51

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

6条回答
  •  误落风尘
    2021-02-07 14:53

        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 _{
    
        }
    

提交回复
热议问题