Reputation: 519
i try to set up an Xcode project based on the template "OpenGL Game". That example has a StoryBoard with one GLKViewController and one GLKView.
I'd like to have:
The problem: - I can't seem to put two GLKViews onto a screen when using a StoryBoard - I can't get GLKViews to work when using a NIB file
I wonder if any of the two ways is possible and what would be the best way to proceed.
Even when setting up just one GLKView and GLKViewController in a NIB file it seems that neither the method update: is called nor the glkView:drawInRect: of the GLKViewController.
How can i best place two GLKViews into an iPad app onto the same screen?
EDIT: Sorry for being imprecise.
Basically what i want to do:
I use Xcode 4.2 for iOS 5.1 for iPad
First approach, use a StoryBoard:
Second approach, delete the StoryBoard and create a NIB file:
Any way would be fine with me, at the moment none works.
Thanks for any hints, Torsten.
SOLVED: I use a NIB file now and i added a PRECONFIGURED combination of GLKViewController / GLKView. Just placing a UIView and a UIViewController and then changing their type does not work.
Upvotes: 3
Views: 3392
Reputation: 400
I ran into this same issue recently, but with only 2 GLKViews instead of 3.
I ended up doing it all programmatically, since the storyboard method didn't seem to be robust enough for this.
What I did was create a "master" GLKViewController that would house all of my other GLKViews/GLKViewControllers.
I then add child subclassed GLKViewControllers with their subsequent views.
The tricky part that I found was that I needed to add the ViewControllers as a child as well as add their views as a child to the "master" view.
GLKViewController master = [[GLKViewController alloc] initWithNibName:nil bundle:nil];
GLKView *masterView = (GLKView *)master.view;
masterView.context = context;
master.view = masterView;
/* I created a constructor with a parameter to identify dimensions and position for rendering */
GLKViewController *child1 = [[SubclassGLKViewController alloc] initWithNibName:nil bundle:nil];
GLKView *child1View = (GLKView *)child1.view;
child1View.context = context;
child1.view = child1View;
GLKViewController *child2 = [[SubclassGLKViewController alloc] initWithNibName:nil bundle:nil];
GLKView *child2View = (GLKView *)child2.view;
child2View.context = context;
child2.view = child2View;
/*It seems all three of these steps are needed*/
[master addChildViewController:child1];
[child1 didMoveToParentViewController:master];
[master.view addSubview:child1View];
Another thing I had to do was implement viewDidAppear in my GLKViewController subclass.
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if(some condition is met)
change frame size to something
else
change frame size to something else
self.view.frame = frame;
}
Hope this helps.
Upvotes: 3