我认为你最好用最后建议的方案 - 将OpenGL视图保持为静态并在滚动视图之外,并移动其内容以匹配滚动视图的移动。
假设你正在使用GLKView
,实现您的glkView:drawInRect:
,使其得到contentOffset
(和可能的bounds
)从您的滚动视图属性,并绘制适当。例如。 (假装你使用GLES 1.0只是因为矩阵操作方法是那么有名):
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// displayArea will be the area the scroll view is
// currently displaying; taking just the bounds would
// likely be fine too
CGRect displayArea;
displayArea.origin = scrollView.contentOffset;
displayArea.size = scrollView.bounds.size;
// assuming (0, 0) in the GL view is in the centre,
// we'll adjust things so that it's in the corner ala
// UIKit
CGPoint centre = CGPointMake(
displayArea.origin.x + displayArea.size.width*0.5f,
displayArea.origin.y + displayArea.size.height*0.5f);
glPushMatrix();
// apply the scroll as per the scroll view
// so that its centre is aligned with our centre
glTranslatef(-centre.x, -centre.y, -1);
/* rest of drawing here */
glPopMatrix();
}
然后自己连作为代表到滚动视图,只是执行:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[glView setNeedsDisplay];
}
为了保证当滚动视图滚动时,GL重绘。
嗨,我正在研究同样的问题,但我无法让我的实施工作。你有没有设法解决你的问题? – Gabor 2016-05-12 14:53:15