Zooming while capturing video using AVCapture in iOS

后端 未结 2 1669
星月不相逢
星月不相逢 2021-01-07 11:21

I am using AVCapture to capture video and save it. But I need to provide zooming option like pinch to zoom or through a zoom button. Also video should be saved in exactly in

2条回答
  •  自闭症患者
    2021-01-07 11:40

    Add UIPinchGestureRecognizer object to your and handle callback like this:

    - (void) zoomPinchGestureRecognizerAction: (UIPinchGestureRecognizer *) sender {
        static CGFloat initialVideoZoomFactor = 0;
    
        if (sender.state == UIGestureRecognizerStateBegan) {
    
            initialVideoZoomFactor = _captureDevice.videoZoomFactor;
    
        } else {
    
            CGFloat scale = MIN(MAX(1, initialVideoZoomFactor * sender.scale), 4);
    
            [CATransaction begin];
            [CATransaction setAnimationDuration: 0.01];
            _previewLayer.affineTransform = CGAffineTransformMakeScale(scale, scale);
            [CATransaction commit];
    
            if ([_captureDevice lockForConfiguration: nil] == YES) {
                _captureDevice.videoZoomFactor = scale;
                [_captureDevice unlockForConfiguration];
            }
        }
    }
    

提交回复
热议问题