How to synchronize OpenGL drawing with UIKit updates

前端 未结 6 557
深忆病人
深忆病人 2020-12-24 02:24

In our app we have UIScrollView above CAEAGLLayer. UIScrollView contains some UIViews (red rectangles). In CAEAGLLayer we draw white rectangles. Centers of white rectangles

6条回答
  •  长情又很酷
    2020-12-24 02:55

    After digging around a little I'd like to extend my previous answer:

    Your OpenGL rendering is immediately done from within the scrollViewDidScroll: method while the UIKit drawing is performed later, during normal CATransaction updates from the runloop.

    To synchronize UIKit updates with the OpenGL rendering just enclose both in one explicit transaction and flush it to force UIKit to commit the changes to backbaordd immediately:

    - (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
        [CATransaction begin];
        [overlayView updateVisibleRect:CGRectMake(...)];
        [openGlView updateVisibleRect:CGRectMake(...)];
        [CATransaction flush]; // trigger a UIKit and Core Animation graphics update
        [CATransaction commit];
    }
    

提交回复
热议问题