0

这是我的代码:

float timeInterval = 1 / [frameRateTextField floatValue];

        recordingTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval
                                                          target:self
                                                        selector:@selector(recordingTimerSelector:)
                                                        userInfo:nil
                                                         repeats:YES];


- (void) recordingTimerSelector:(NSTimer*)timer{
    NSXMLElement *timecode = [[NSXMLElement alloc] initWithName:@"timecode"];
    [timecode setStringValue:[NSString stringWithFormat:@"%@,%@,%@,%@,%@",[DMXChannelArray objectAtIndex:0], [DMXChannelArray objectAtIndex:1], [DMXChannelArray objectAtIndex:2], [DMXChannelArray objectAtIndex:3], [DMXChannelArray objectAtIndex:4]]];

    [root addChild:timecode];

    time = time + 1;
    [theRecordingTime setStringValue:[NSString stringWithFormat:@"%d", time]];
}

这是最好的方法吗?我基本上是在制作分辨率为 30FPS 的“录像机”。有没有办法让它与实际时间一致,而不是成为一个单独的实体?它可能会使它更准确。喜欢:

10:40:41.0 - record element
10:40:41.3 - record element
10:40:41.6 - record element

谢谢!

4

1 回答 1

0

You can get the current number of seconds since the reference date by asking NSDate for it.

Get that time interval when you start your timer, and then every time it fires, and subtract the starting time interval from the current one to get the number of seconds since you started.

于 2013-01-19T03:12:03.333 回答