首页 > 技术文章 > AVCapture中实现拉近拉远镜头

sunyanyan 2016-04-11 14:41 原文

需要用到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);

推荐阅读