私は私の最初の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]];
}