Adding GLKView via storyboard and programatically

1.2k views Asked by At

I am adding a GLKView to a UIView within a UIViewController. Eventually I will split the code out to use a UIViewController and GLKViewController, but for now my hands are tied and need to use the UIViewController.

My issue is that when I add the GLKView to the UIVIew via the storyboard, everything works fine. When I try to add the GLKView programmatically it doesn't seem to get initialized quite right. It shows up grey.

The only difference in my implementation aside from using an IBOutlet is that I call the first and last lines in the code block below.

glview = [[GLKView alloc] init]; // Non storyboard
[glview setContext:context];
[glview setDelegate:self];
[glview setUserInteractionEnabled:YES];
[self.view addSubview:glview]; // Non storyboard

After the initialization I set up an AVCapture session. I set the frame on my GLKView in the controllers viewWillAppear function. Do you see any reason why my GLKView isn't getting initialized correctly?

1

There are 1 answers

0
Joe Andolina On

The application is managing the drawing routine so I needed to disable the "enableSetNeedsDisplay" on my programmatically created GLKView. The following code fixed my issue. Take note of the the penultimate line.

glview = [[GLKView alloc] init];
[glview setContext:context];
[glview setDelegate:self];
[glview setUserInteractionEnabled:YES];
[glview setEnableSetNeedsDisplay:NO]; // HERE IS THE FIX
[self.view addSubview:glview];