做人脸识别的项目中用到,顺便做了下笔记
//上锁
-(void)changeDevicePropertySafety:(void (^)(AVCaptureDevice *captureDevice))propertyChange{
AVCaptureDevice *captureDevice= [_videoInput device];if ([captureDevice lockForConfiguration:nil]) {
propertyChange(captureDevice);
[captureDevice unlockForConfiguration];
}
}
//缩放的实现点击
-(void)FocalLength{
NSLog(@"调整焦距");
[self changeDevicePropertySafety:^(AVCaptureDevice *captureDevice) {
if (captureDevice.videoZoomFactor == 1.0) {
//缩放倍数
CGFloat current = 1.5;
if (current < captureDevice.activeFormat.videoMaxZoomFactor) {
[captureDevice rampToVideoZoomFactor:current withRate:10];
}
}else{
//1.0 表示缩放回到原来的大小(复原)
[captureDevice rampToVideoZoomFactor:1.0 withRate:10];
}
}];
}