Attempting to add landscape IB buttons to an openGL View

Posts: 110
Joined: 2009.07
Post: #1
Hi folks,

I've written too much of my own GUI code over the last few months and decided to bite the bullet. It's time to add some UIKit stuff over the top of my lovely landscape openGL screen.

I've looked at 2 ways of doing this:-

- Adding a view controller and making the EAGL view a sub-view of it
- NOT adding a Simply adding buttons over the top of the EAGL view

I've tried the former and have had no success in getting the text buttons to display in Landscape format.

Any suggestions?
1) How would you best add gui buttons to an EAGLView based app without destroying frame-rate? (Note: I'm not asking for help with my current frame rate - it's great at the moment as I've done everything correctly. These additional buttons will only be displayed when choosing options, and then disappear).

2) How do you get IB created buttons to understand that you've defaulted to a landscape screen. IB is allowing me to change the ViewController to landscape, and draws the buttons nice and side-on. This is then completely ignored when actually creating the buttons at runtime.

Any help much appreciated. If I don't figure this out soon I'll just end up making my own GUI... again (I've been doing this a while, so this'll be about my 6th GUI).
Fluttermind - Games for Everyone
Quote this message in a reply
Posts: 40
Joined: 2009.05
Post: #2
To get the standard automatic support for different orientations you need to use a UIViewController and override the shouldAutorotateToInterfaceOrientation method to return true for landscape orientations.

This will apply the appropriate transforms to your view.

[/code]However, from what I understand there were/are? some performance implications of having your EAGLView transformed in this way.

If you are only supporting one landscape orientation then you can just manually add a transform to your button views to get them to appear in the right place. I'd suggest adding UIView on top of your EAGLView and then add the buttons to that. You can then just transform the UIView as required to get it into landscape mode.

If you want to support all the orientations then you can you can do this:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:nil];
and then you'll get notifications when the device orientation changes
-(void) orientationChanged {
    UIDeviceOrientation deviceOrientation=[UIDevice currentDevice].orientation;
    .. manually transform your views ...

You don't need a view controller for this to work - but you will get all the device orientations (including face up, face down etc...) not just portrait/landscape.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Landscape app sometimes thinks portrait bruss14 1 3,391 Dec 30, 2009 01:32 PM
Last Post: bruss14
  Chipmunk moonbuggy dynamic landscape wonza 5 5,530 Nov 6, 2009 01:08 AM
Last Post: wonza
  2D Control Buttons on Top of 3D OpenGl. Bersaelor 1 5,458 Sep 23, 2009 09:56 AM
Last Post: Skorche
  iPhone opengl 2d sprites landscape mode mnorton 6 7,527 Sep 9, 2009 08:27 PM
Last Post: mnorton
  How do I misuse volume buttons? jaber 15 9,611 Aug 26, 2009 11:24 AM
Last Post: Frank C.