当变量值改变时,是否执行方法的一部分?

时间:2017-07-21 15:12:35

标签: ios objective-c swift sceneview

我正在将一些正在运行的swift代码转换为Objective-C,它将SceneView呈现为m4v视频,并且渲染处理方法具有仅在满足条件时执行的return语句。

swift代码如下:

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];
    }
}

感谢任何帮助,我很抱歉最后一个括号格式,似乎无法正确。

谢谢

0 个答案:

没有答案