Skip to main content

Posts

Showing posts with the label tracking

CADisplayLink with NSRunLoopCommonModes not executed for every frame when tracking UIScrollView?

I am trying to execute a small piece of code on every single frame in a regular (non-OpenGL) iPhone app. The goal is to have a frame counter so that I can measure (rather than guess) where the slow points in the app are and fix them to create a better user experience. What I've done so far is register a CADisplayLink for all modes (including tracking): CADisplayLink *displayLink = [[CADisplayLink displayLinkWithTarget:self selector:@selector(frame)] retain]; [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; The code that is executed looks like this (lastDraw is a NSDate* and count an int): - (void) frame { NSDate *newDate = [NSDate date]; if([newDate timeIntervalSinceDate:lastDraw] >= 1) { label.text = [NSString stringWithFormat:@"%d FPS", count]; count = 0; [lastDraw release]; lastDraw = [newDate retain]; } count++; } The idea here is to get an update every one second as to how many frames were drawn in the past s