나는 처음으로 iphone 앱을 완성하는 데 아주 가깝습니다. 기뻤습니다. UILabel에 현재 시간 (NSDate)을 표시하는 NSTimer를 통해 현재 시간을 사용하여 실행중인 시간 코드를 추가하려고합니다. NSDate는 시간, 분, 초, 밀리 초를 보여 주며 잘 작동합니다. 하지만 밀리 초 대신 초당 24 프레임을 표시해야합니다.NSTimer 및 NSDateFormatter를 사용하여 시간 코드 표시
문제는 초당 프레임을시, 분, 초로 100 % 동기화해야하므로 개별 타이머에 프레임을 추가 할 수 없다는 점입니다. 나는 그것을 시험해 보았지만 프레임 타이머가 날짜 타이머와 동기화되어 실행되지 않았다.
누구든지 나를 도와 줄 수 있습니까? 초당 24 프레임으로 포맷 된 날짜 타이머를 가질 수 있도록 NSDateFormatter를 사용자 정의하는 방법이 있습니까? 지금은 시간, 분, 초 및 밀리 초 형식으로 제한됩니다. 이 초, 그래서 일부는 당신에게 밀리 초를 줄 것이다 -
여기에 당신이 당신의 NSDate
에서 밀리 초를 추출하는 것이
-(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]];
}
일부 재생 후, 나는 아직도 이것을 구현하는 방법을 잘 모르겠습니다. 나는 당신이 제안한 것을 성공적으로 할 수 있었지만 실제로 초당 24 프레임의 변환을하는 수학의 전체 덩어리를 놓치고있는 것 같습니다. 초당 100 밀리 초를 표시하는 대신 매초마다 0-23의 숫자를 표시해야하며 NSTimer와 완벽하게 동기화되어 각 초가 끝나면 실제로 완료되고 다시 시작해야합니다. –