I've asked a more general question about how CADisplayLink
and drawRect
behave here, but as that question doesn't have any answers yet, I thought I'd ask a more specific one: has anyone managed to get an app to run at 60fps with a drawRect
method that takes ~10ms to execute?
In my app, I configure a CADisplayLink
like so:
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
and the update
method simply calls setNeedsDisplay
on my custom UIView (as well as checking for skipped frames):
- (void)update
{
static CFTimeInterval timestamp = 0;
// check for skipped frame
CFTimeInterval newTimestamp = displayLink.timestamp;
if ((newTimestamp - timestamp) > (displayLink.duration * (displayLink.frameInterval + 0.5)))
NSLog(@"Frame skipped!");
timestamp = newTimestamp;
[myView setNeedsDisplay];
}
This begins to skip frames as soon as drawRect
takes more than 4 or 5 milliseconds. For my purposes, it will need up to around 10-11ms, but I thought that given 1/60fps = 16.7ms this should be no problem.
Has anyone achieved this? What am I doing wrong?