UIScrollView broken and halts scrolling with OpenG

2019-02-14 18:12发布

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.

4条回答
趁早两清
2楼-- · 2019-02-14 18:40

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

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

查看更多
戒情不戒烟
3楼-- · 2019-02-14 18:48

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/.

查看更多
劫难
4楼-- · 2019-02-14 18:51

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.

查看更多
ら.Afraid
5楼-- · 2019-02-14 19:00

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

查看更多
登录 后发表回答