UIScrollView broken and halts scrolling with OpenG

2019-02-14 18:27发布

问题:

Solution note, Not a question.

UIScrollView suspends OpenGL rendering by preventing firing CADisplayLink tick when CADisplayLink registered with NSDefaultRunLoopMode.

But, if you use NSRunLoopCommonModes to solve this, UIScrollView will halt scrolling at burst scrolling. And after once halted, it does not scroll again. (broken)

And registering CADisplayLink in other thread/runloop (as described in answer of this question: CADisplayLink stops updating when UIScrollView scrolled) reduces UIScrollView behavior breaking, but cannot eliminate.

回答1:

Edit: Woops, misread your post. Nevermind

As mentioned in this post, you can solve this issue by switching run loop modes. Animation in OpenGL ES view freezes when UIScrollView is dragged on iPhone



回答2:

This is also explained with a walk through in Apple's WWDC 2012, session 223: "Enhancing user experience with scroll views", second half: https://developer.apple.com/videos/wwdc/2012/.



回答3:

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.



回答4:

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

Otherwise, call render & present code at -scrollViewDidScroll too, not only in CADisplayLink's tick callback.