Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CADisplayLink stops updating when UIScrollView scrolled

Title is quite self explanatory, but I have some animation being done in a loop triggered by CADisplayLink. However, as soon as I scroll a UIScrollView I have added to my view hierarchy, the animation stops immediately, only to return again when scrolling has completely stopped and come to a standstill....

Anyway to cancel this behaviour?

like image 888
Tricky Avatar asked Mar 26 '10 15:03

Tricky


5 Answers

You can also mitigate the effects of this issue by using NSRunLoopCommonModes instead of NSDefaultRunLoopModes:

[displayLink addToRunLoop:[NSRunLoop currentRunLoop]
                  forMode:NSRunLoopCommonModes];
like image 108
nornagon Avatar answered Nov 10 '22 06:11

nornagon


Run the display link (using -addToRunLoop:forMode:) on another thread with another run loop. So create a new thread, create a run loop on that thread, and run the CADisplayLink on that thread/run loop.

like image 31
Steven Canfield Avatar answered Nov 10 '22 06:11

Steven Canfield


Use UITrackingRunLoopMode. It's specifically designed for scrolling stuffs.

Otherwise, just call render & present routine at -scrollViewDidScroll.

UIScrollView broken and halts scrolling with OpenGL rendering (related CADisplayLink, NSRunLoop)

like image 22
eonil Avatar answered Nov 10 '22 06:11

eonil


Here you can find a better (and more complex) solution:

Animation in OpenGL ES view freezes when UIScrollView is dragged on iPhone

that allows you to use 'NSRunLoopCommonModes' and avoids OpenGL freezing when holding a finger without scrolling.

This is related to what Doug found (setting the frame interval of CADisplayLink to 2 instead of 1 fixing UIScrollView).

like image 4
Ricardo Sanchez-Saez Avatar answered Nov 10 '22 05:11

Ricardo Sanchez-Saez


Actually CADisplayLink support multiple RunloopMode. try this:

    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:UITrackingRunLoopMode];
    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
like image 4
ooOlly Avatar answered Nov 10 '22 05:11

ooOlly