GLKViewControllerDelegate getting blocked

放肆的年华 提交于 2020-01-24 02:53:07

问题


I have a GLKViewController to handle some OpenGL drawing. I have the glkView:drawInRect and update method both implemented and have the preferredFramesPerSecond property set to 30 (the default).

The problem is that the delegate methods stop firing when the user interacts with other part of the app. The two cases that I have seen this happen on is when the user scrolls a UITableView or interacts with a MKMapView.

Is there a way to make sure these delegates always fire, regardless of what the rest of the app is doing. The only time I want these to stop is when the app enters the background (which is does automatically).


回答1:


The reason for this is that during scrolling in a table view or map view the runloop is in UITrackingRunLoopMode which has a higher priority than the default mode. This prevents some events from firing in order to guarantee a high scrolling performance.

To solve your problem you must set up your own rendering loop instead of relying on the GLKViewController.

  • First set enableSetNeedsDisplay of the GLKView to NO (should be set automatically when using GLKViewController).
  • set preferredFramesPerSecond to 0 (or maybe 1) to disable the rendering loop of GLKViewController or don't use GLKViewController at all
  • Import the QuartzCore framework: #import <QuartzCore/QuartzCore.h>
  • create a CADisplayLink and schedule it in NSRunLoopCommonModes:
CADisplayLink* displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(render:)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
  • optional: set the frameInterval of displayLink to 2 (= half the framerate)
  • the render method:
- (void)render:(CADisplayLink*)displayLink {
    GLKView* view = (GLKView*)self.view;
    [view display];
}

I haven't tested this, so tell me if it works!



来源:https://stackoverflow.com/questions/10080932/glkviewcontrollerdelegate-getting-blocked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!