1

私は私の最初のiphoneアプリを完成させるのに非常に近いです、そしてそれは喜びでした。UILabelに現在の時刻(NSDate)を表示するNSTimerを介して、現在の時刻を使用して実行中のタイムコードを追加しようとしています。NSDateは正常に機能しており、時、分、秒、ミリ秒を表示しています。ただし、ミリ秒ではなく、1秒あたり24フレームを表示する必要があります。

問題は、1秒あたりのフレーム数を時間、分、秒と100%同期する必要があるため、別のタイマーにフレームを追加できないことです。それを試して動作させましたが、フレームタイマーが日付タイマーと同期して実行されていませんでした。

誰かがこれで私を助けることができますか?NSDateFormatterをカスタマイズして、1秒あたり24フレームでフォーマットされた日付タイマーを使用できるようにする方法はありますか?現在、フォーマットは時間、分、秒、ミリ秒に制限されています。

これが私が今使っているコードです

-(void)runTimer {
 // This starts the timer which fires the displayCount method every 0.01 seconds
 runTimer = [NSTimer scheduledTimerWithTimeInterval: .01
            target: self
             selector: @selector(displayCount)
             userInfo: nil
              repeats: YES];
}

//This formats the timer using the current date and sets text on UILabels
- (void)displayCount; {

 NSDateFormatter *formatter =
 [[[NSDateFormatter alloc] init] autorelease];
    NSDate *date = [NSDate date];

 // This will produce a time that looks like "12:15:07:75" using 4 separate labels
 // I could also have this on just one label but for now they are separated

 // This sets the Hour Label and formats it in hours
 [formatter setDateFormat:@"HH"];
 [timecodeHourLabel setText:[formatter stringFromDate:date]];

 // This sets the Minute Label and formats it in minutes
 [formatter setDateFormat:@"mm"];
 [timecodeMinuteLabel setText:[formatter stringFromDate:date]];

 // This sets the Second Label and formats it in seconds
 [formatter setDateFormat:@"ss"];
 [timecodeSecondLabel setText:[formatter stringFromDate:date]];

 //This sets the Frame Label and formats it in milliseconds
 //I need this to be 24 frames per second
 [formatter setDateFormat:@"SS"];
 [timecodeFrameLabel setText:[formatter stringFromDate:date]];

}
4

3 に答える 3

1

からミリ秒を抽出することをお勧めしますNSDate-これは秒単位であるため、分数はミリ秒になります。

次に、単純なフォーマット文字列を使用して、NSStringメソッドstringWithFormat: を使用して値を追加します。

于 2010-05-17T09:37:53.463 に答える
0

これは、かなり簡単に再利用できる Processing/Java の同等物です。

String timecodeString(int fps) {
  float ms = millis();
  return String.format("%02d:%02d:%02d+%02d", floor(ms/1000/60/60),    // H
                                              floor(ms/1000/60),       // M
                                              floor(ms/1000%60),       // S
                                              floor(ms/1000*fps%fps)); // F
}
于 2011-09-18T21:09:43.447 に答える