2012-02-20 54 views
3

我在iPad上创建一个绘图应用程序,用户可以在绘图中滚动并滚动。 (想象一下画布宽度为4000像素,视图端口宽度为1024)目前,我使用OpenGL绘制图形,宽度为1024,效果很好。当我将UIView的帧大小更改为4000时,出现“未完成帧缓冲区对象8cd6”。当我将它缩小到2000的宽度时,我最终得到了“古怪”的结果。我知道我可以正确操作框架,因为框架宽度为500会产生正确的结果。iOS OpenGL图层和UIScrollView

我也在考虑留下宽度1024并移动OpenGL层的相机,但是如何使用我设置的UIScrollView?所以我现在不确定该做什么。有什么建议?

在此先感谢

P.S.代码主要基于GLPaint示例Apple提供的here

+0

嗨,我正在研究同样的问题,但我无法让我的实施工作。你有没有设法解决你的问题? – Gabor 2016-05-12 14:53:15

回答

4

我认为你最好用最后建议的方案 - 将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重绘。

2

我强烈建议您使用OpenGL相机进行缩放,而不是尝试在UIScrollView中使用它。这将是一个更多的工作来建立,但最终走向恕我直言。