做人臉識別的項目中用到,順便做了下筆記
//上鎖
-(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];
}
}];
}