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);
posted @ 2016-04-11 14:41  孙焱焱  阅读(860)  评论(0编辑  收藏  举报