仅当我使用updatedMetadataObjectForMetadataObject来调整previewLayer时,问题是不稳定的(每次更新时两个大小之间的大小跳转)大小。
for(AVMetadataObject *metadataObject in metadataObjects) {
if([metadataObject.type isEqualToString:AVMetadataObjectTypeFace]) {
// Take an image of the face and pass to CoreImage for detection
AVMetadataObject *metadataObjectR=[previewLayer transformedMetadataObjectForMetadataObject:metadataObject];
previewLayer.bounds = CGRectMake(previewLayer.bounds.origin.x,previewLayer.bounds.origin.y, metadataObjectR.bounds.size.width,metadataObjectR.bounds.size.height);
创建previewLayer的代码(previewViewLayer是CALayer)
[captureSession addInput:vInput];
[captureSession setSessionPreset:AVCaptureSessionPresetPhoto];
previewViewLayer = [self.view layer];
[previewViewLayer setBackgroundColor:(__bridge CGColorRef _Nullable)([UIColor blackColor])];
previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:captureSession];
[previewLayer setFrame:[previewViewLayer bounds]];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[previewViewLayer addSublayer:previewLayer];
答案 0 :(得分:0)
我不知道你想做什么。函数transformationMetadataObjectForMetadataObject,返回在previewLayer坐标中的metaDataObject,所以它的边界是metaDataObject的框架。但是你用这个框架来设置previewLayer的界限。预览层的框架不应该改变,因为它用于预览相机。你应该使用新的metaDataObject界限来改变图层的框架来指示面部。 / p>