1

我正在将一些工作 swift 代码转换为将 SceneView 渲染为 m4v 视频的 Objective-C,并且渲染处理方法有一个返回语句,该语句仅在满足条件时执行。

快速代码如下:

func renderScene() {    
    self.videoRenderer.delegate = self
    var options = VideoRendererOptions()
    options.sceneDuration = self.rotationDuration * 
    TimeInterval(self.totalRotations)
    options.videoSize = CGSize(width: 1280, height: 720)
    options.fps = 60

    let startTime = Date()
    self.videoRenderer.render(
    scene: arView.scene,
    withOptions: options,
    until: {
        print(self.rotations, self.totalRotations)
        return self.rotations >= self.totalRotations
    },
    andThen: {
        outputPath in

        print(
            String(format:"Finished render in time: %.2fs", startTime.timeIntervalSinceNow * -1)
        )

        PhotosUtil.saveVideo(atPath: outputPath)

        let alert = UIAlertController(title: "Done", message: "A new video has been added to the Camera Roll", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
        self.present(alert, animated: true)
        }
    )
}

此快速代码正在运行,并在满足直到条件时返回(self.rotations >= self.totalRotations)。

我的 Objective-C 代码反映了这段代码,但由于某种原因,直到中的部分没有被触发。在这种情况下,函数应该根据 until 块中的布尔值返回。

-(void)renderScene{
    videoRenderer.delegate = self;
    struct VideoRendererOptions options;
    options.videoSize = CGSizeMake(1280, 720);
    options.fps = 60;

    NSDate *startTime = [NSDate date];
    [videoRenderer render:_sceneView.scene withOptions:options until:^BOOL{
        return !isRecording;
    } andThen:^(NSString * outputPath) {
        NSLog(@"%@", [NSString stringWithFormat:@"Finished render time in %.2fs", ([startTime timeIntervalSinceNow] * - 1)]);
        [PhotoUtil saveVideoAtPath:outputPath];
        [PSIAlertUtility showAlertTitle:@"Video Saved" message:@"Video has been added to your camera roll yo"];
    }];}

我还有一个方法可以改变 isRecording 的值,并根据这个值调用渲染函数。如下:

-(void)recordPressed{
    isRecording = !isRecording;
    if (isRecording) {
        [self renderScene];
    }
}

将不胜感激任何帮助,我对最后一个括号格式感到抱歉,似乎无法正确处理。

谢谢

4

0 回答 0