integrating Xib with an isgl3d test

115 views
Skip to first unread message

Matt

unread,
Jan 8, 2012, 9:14:38 PM1/8/12
to isgl3d
Ive been playing around with the PhysicsTest portion from the download
bundle and I was wondering if anyone has integrated an xib with any of
these tests or tutorials, Ive been able to integrate an xib with a
basic opengl project in the past but with isgl3d I'm not having any
luck. Ive even tried following mach cubed's instructions from adding
an xib menu to an isgl3d app and I can never get it to display. Any
help would be appreciated whether it be a PM or post

Rudi

unread,
Jan 9, 2012, 7:16:48 AM1/9/12
to isgl3d
Hi Matt,

I combined several xib or rather nib files with an isgl3d project.
How do you use xib/nib files? If I remember it right you need to
declare a custom UIViewController at least. You can also mix
the views if you want. You just have to add your view of the
custom UIViewController as a subview. Can you describe how
you use your xib/nib files?

Rudi

Matt

unread,
Jan 11, 2012, 12:14:51 AM1/11/12
to isgl3d
Thank you for your response Rudi... unfortunately I've gotten pretty
hung up, probably some rookie mistake but ya never know. Lets say we
start with one of the test projects and declare a UIViewController in
the .h file and add a UIButton, I want to be able to see the button
from within the isgl3d app, I've linked the button from the file owner
in interface builder to the button, I know the mistake is in the
method createViews as even when I specify a completely white
viewcontroller with a few buttons absolutely nothing display. I've
played with the UITest app and I can replicate as long as my 2D menus
are created within isgl3d and not using the UIKit. If someone has an
example of a tutorial/test with an xib window could they post for use
for the community or could someone make this as I think this would be
an important reference for everyone.

Rudi

unread,
Jan 11, 2012, 4:59:47 AM1/11/12
to isgl3d
Hi Matt,

I know what you mean. Sometimes there are days where
you do not even solve the easiest thing.

But in this case I can help you out. As far as I remember
it was not sufficient to have a UIViewController declared
in your application delegate or whereever you use the controller.
I decided to provide a class header and implementation file separately
for each xib/nib file I want to use in an isgl3d project.

Your app would contain the three files at least:
YourNibView.nib
YourNibViewController.h
YourNibViewController.mm

In your application delegate you can then allocate the controller like
this:

- (void) applicationDidFinishLaunching:(UIApplication*)application {
...
self.yourNibViewController = [[YourNibViewController alloc]
initWithNibName:@"YourNibView" bundle:nil];

// Create the UIWindow
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]
bounds]];
[_window addSubview:yourNibViewController.view]; // here it is

{
// just to keep it simple - could be done later or put in a separate
method
[Isgl3dDirector sharedInstance].backgroundColorString =
@"333333ff";
[Isgl3dDirector sharedInstance].deviceOrientation =
Isgl3dOrientationLandscapeRight;
_viewController = [[Isgl3dViewController alloc] initWithNibName:nil
bundle:nil];
_viewController.wantsFullScreenLayout = YES;
Isgl3dEAGLView * glView = [Isgl3dEAGLView viewWithFrameForES1:
[_window bounds]];

// Set view in director
[Isgl3dDirector sharedInstance].openGLView = glView;
[Isgl3dDirector sharedInstance].autoRotationStrategy =
Isgl3dAutoRotationByUIViewController;
[Isgl3dDirector sharedInstance].allowedAutoRotations =
Isgl3dAllowedAutoRotationsLandscapeOnly;
// Set the animation frame rate
[[Isgl3dDirector sharedInstance] setAnimationInterval:1.0/60];
_viewController.view = glView;
}


[_window makeKeyAndVisible];

// just to keep it simple - could be done later or put in a separate
method like above
[[Isgl3dDirector sharedInstance] run];
}


You will see your xib/nib view integrated in the isgl3d project now.
Ok, what's next.
Imagine you have a HelloWorldView class that derives from
Isgl3dBasic3DView and contains
your scene. I would not assign it to the UIWindow instance in the
method above. I would
provide a method to put it into the main window whenever it is
necessary. For this simple
usage you can use a switchViews method in your application delegate as
follows:

- (void) switchViews
{
if (_viewController.view.superview == nil) {
// add the view to the window as subview
[_window addSubview:_viewController.view];
[_window bringSubviewToFront:_viewController.view];

[yourNibViewController.view removeFromSuperview];
if (!_helloWorldView)
_helloWorldView = [HelloWorldView view];

} else
{
[_window addSubview:yourNibViewController.view];
[_window bringSubviewToFront:yourNibViewController.view];

[_viewController.view removeFromSuperview];
}
}

And to complete this simple example you invoke the switchViews method
from an IBAction
method in your controller class YourNibViewController.

- (IBAction)buttonPressed
{
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication
sharedApplication] delegate];
if (appDelegate) {
[appDelegate switchViews];
}
}

I hope that this small and simple example can help to solve your
problem.
I also agree with you that such examples belong to the isgl3d bundle
to show how the usage of
xib/nib files can look like.

Rudi

Juan Cardelino

unread,
Jan 31, 2012, 5:54:08 AM1/31/12
to isgl3d
Hi there.
I did something similar, but I will keep to myself until I know more
of iOS and obj-C because it is a mess. Essentially, I've made a xib
file with the whole interface and then hook the isgl3d view to one of
the views there. Everything works fine, but there are some strange
things. If I manage to simplify it, I will post it and maybe you can
help me with it.

sooonism

unread,
Apr 15, 2013, 10:44:00 AM4/15/13
to isg...@googlegroups.com
Hi Rudi,

I tried your method and it works. But i have a problem:

I can switch view but everytime it switch back to isgl3dview, I can see double "Hello World" spinning. It seems like i need to do more then just removeFromSuperView. Any idea how to solve this??
Thanks!

sooon

sooonism

unread,
Apr 16, 2013, 9:03:44 PM4/16/13
to isg...@googlegroups.com
Hi,

I finally figured out how to get this to work.


I just want to share with whoever want to do the same thing. Thanks!
Reply all
Reply to author
Forward
0 new messages