CADisplayLink and drawRect

I need help to better understand how they behave CADisplayLinkand drawRect, so that I can figure out how to keep the application running at a smooth 60 frames per second. So far, my (supposedly incorrect) understanding is as follows:

1) CADisplayLinkcalls the specified selector when the display is updated (the so-called "v-sync" event, approximately every 16 ms).

2) iOS uses double buffering, which means that while one buffer is being displayed, we can prepare (reverse) to another, and two will be replaced with the next v-sync event.

3) Thus, since the display line was triggered, I have about 16 ms to make sure that all calculations and drawing necessary for the next frame have been completed, so that everything will be ready by the time the buffers are replaced and the screen refreshes .

4) The drawRect method of the custom UIView accesses the back buffer, so any custom drawing is displayed in the next v-sync event after the method is called drawRect.

How it works? (And what happens if the next v-sync event happens before I finish drawing to the back buffer?)

Then, how do I use CADisplayLinkto redraw custom UIViews? I tried calling setNeedsDisplaywhenever the image link appears, but there is a delay before the start of the drawRect method:

2014-12-10 19:17:21.000 myApp[39487:60b] Display link fired.
2014-12-10 19:17:21.001 myApp[39487:60b] Sending setNeedsDisplay
2014-12-10 19:17:21.012 myApp[39487:60b] drawRect beginning
2014-12-10 19:17:21.013 myApp[39487:60b] drawRect finished
2014-12-10 19:17:21.017 myApp[39487:60b] Display link fired.
2014-12-10 19:17:21.018 myApp[39487:60b] Sending setNeedsDisplay
2014-12-10 19:17:21.029 myApp[39487:60b] drawRect beginning
2014-12-10 19:17:21.031 myApp[39487:60b] drawRect finished
2014-12-10 19:17:21.033 myApp[39487:60b] Display link fired.

, drawRect . drawRects 10 . 5ms , drawRect, ! , 11 , " " drawRect! ?

drawRect , :

2014-12-10 19:24:41.000 myApp[39495:60b] Display link fired.
2014-12-10 19:24:41.001 myApp[39495:60b] Sending setNeedsDisplay
2014-12-10 19:24:41.002 myApp[39495:60b] drawRect beginning
2014-12-10 19:24:41.003 myApp[39495:60b] drawRect finished
2014-12-10 19:24:41.016 myApp[39495:60b] Display link fired.
2014-12-10 19:24:41.017 myApp[39495:60b] Sending setNeedsDisplay
2014-12-10 19:24:41.018 myApp[39495:60b] drawRect beginning
2014-12-10 19:24:41.020 myApp[39495:60b] drawRect finished
2014-12-10 19:24:41.032 myApp[39495:60b] Display link fired.

. Apple , " drawRect ". ? 16 , ?

+3

All Articles