自己用avcapture实现自定制相机,系统相机是可以拉近拉远镜头的,网上搜寻了半天始终没有发现,刚才又翻看了半天的api接口,终于找到了,原来他藏在AVCaptureConnection中,videoScaleAndCropFactor:缩放裁剪系数。简单写了下使用方法:
- 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);
有一点需要注意:the videoScaleAndCropFactor property may be set to a value in the range of 1.0 to videoMaxScaleAndCropFactor,videoScaleAndCropFactor这个属性取值范围是1.0-videoMaxScaleAndCropFactor,如果你设置超出范围会崩溃哦!