AVCapture中实现拉近拉远镜头
需要用到AVCaptureConnection的两个属性
- @property(nonatomic) CGFloat videoScaleAndCropFactor
- @property(nonatomic, readonly) CGFloat videoMaxScaleAndCropFactor
videoScaleAndCropFactor这个属性取值范围是1.0-videoMaxScaleAndCropFactor
示例:
AVCaptureStillImageOutput* output = (AVCaptureStillImageOutput*)[self.captureSession.outputs objectAtIndex:0];
AVCaptureConnection *videoConnection = [output connectionWithMediaType:AVMediaTypeVideo];
CGFloat maxScale = videoConnection.videoMaxScaleAndCropFactor;
CGFloat zoom = maxScale / 50;
if (zoom < 1.0f || zoom > maxScale)
{
return;
}
videoConnection.videoScaleAndCropFactor += zoom;
self.preVideoView.transform = CGAffineTransformScale(self.preVideoView.transform, zoom, zoom);