我正在开发一款需要显示运行时间码时钟的iPhone / iPad应用程序.我已经让它显示正确的小时,分钟和秒,使用此代码没有问题:
- (void) viewDidLoad { // Start the Timer method for here to start it when the view loads. runTimer = [NSTimer scheduledTimerWithTimeInterval: .01 target: self selector: @selector(updatedisplay) userInfo: nil repeats: YES]; } - (void)updatedisplay { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; NSDate *date = [NSDate date]; // display each hour,minute,second and frame. [formatter setDateFormat:@"hh"]; [timecodeHourLabel setText:[formatter stringFromDate:date]]; [formatter setDateFormat:@"mm"]; [timecodeMinuteLabel setText:[formatter stringFromDate:date]]; [formatter setDateFormat:@"ss"]; [timecodeSecondLabel setText:[formatter stringFromDate:date]]; }
问题是我需要每秒显示帧数.我知道计算1/24 * 1000会给我一帧中的毫秒数.我只是不知道如何使NSDate和NSTimer函数与此代码一起使用,并允许它根据运行时间码的需要尽快更新UILabel.
有什么建议?