Rotate the app for iphone/ipad

Is it possible in Juce to rotate the app for iphone/ipad, so I can use it in landscape mode as opposed to the portrait mode?
Also, are there any hooks in juce for the iphone typical features like checking accelerometers, orientation, or multi touch?

I’ve not done that yet - I’ll need to come up with a nice, cross-platform way of handling rotation. It’s on the to-do-list!

sounds good. In the meantime, can I put the shouldAutorotateToInterfaceOrientation somewhere in the juce code to ‘hack’ it?
For some reason, my ipad simulator doesn’t respond to rotating the device.

Yes, you’d have to hack it into the native code somewhere, probably in UIViewComponentPeer


Please make it public, when you have found a nice place for that hack. :slight_smile:

Hmm. Looks like it might be quite bit of hacking. I’ve managed quite easily to add UIViewController to control the JuceUIView within the UIViewComponentPeer which has:

	return YES;

… implemented. BUT the geometry goes all over the place since I suspect nothing else knows that the thing has been rotated!

So with a simple window:[attachment=2]Picture 1.png[/attachment]

Rotated right:[attachment=1]Picture 2.png[/attachment]

And rotated back to portrait and then moving the window:[attachment=0]Picture 3.png[/attachment]

(Notice it’s squished.)

Ok… thanks! It’s on my to-do-list to look at this, will try to do so soon!

Did you go any further than this Martin? When your app rotated, were the mouse events in the right place?


Martin, please could you post your code to attach a UIViewController so that can go in? Even if Jules picks a nicer way to do rotation than platform native, it would be useful.

On the other hand, Jules, since iPad and iPhone are inherently rotatable, whereas most other devices that other OS’s support aren’t, wouldn’t it be reasonable to use platform calls to rotate?

The logic being that if the device can rotate, the OS will include such a function and Juce should use it as the most efficient way to rotate?

I believe the iPad/iPhone system will rotate the app and all events as well, for ‘free’?


Yes, definitely - I just need to find some time to sit down and see how it all works…

This was the last version I played with but no, I didn’t any further.

I think uncommenting lines 316+317 got the behaviour I showed earlier in the thread.

Ok, thank you. I’ll dig around a bit. If that controller is getting the rotate events (?) then it may also get resize stuff, or else we can just trigger from that.

I guess, since it was an experiment, you did the simplest - looks like it’s a dangling pointer right now?


yes it was a quick experiment, the JuceUIViewController does dangle. Sorry about that…

I assume nobody has a breakthrough yet?

Here’s a slightly simpler problem: I need to make my app work in landscape, not rotate, fixed landscape.
Anybody got an idea how to accomplish this?

I can rotate all my bitmaps and texts including the mouse cursor, use very simple UI components, and then pretend i’m in portrait mode?

Same setting. Plus a property list setting to tell the app what position to start in.

Maybe you’ll be the one to finish this task? In general, if you get the correct code, post it, and Jules will grab it, laugh amiably at your efforts, and put it into the codebase.


(1) wanted to start in landscape mode so added the following to info.plist
Key = UIInterfaceOrientation
Value = UIInterfaceOrientationLandscapeRight

(2) downloaded Martin Robinson’s which handles creating a UIViewController.

(3) modified the main DocumentWindow as follows:

        : DocumentWindow (T("JUCE Hello World!"),
        // Create an instance of our main content component, and add it
        // to our window.

		//fullscreen with no titlebars - it's and iPad app afterall!
		MainComponent* const contentComponent = new MainComponent();
        setContentComponent (contentComponent, true, false);

		setVisible (true);

got rid of the titlebars and made everything fullscreen. Also I changed setContentComponent (contentComponent, true, true) to (contentComponent, true, false).

also had to override paint in the main DocumentWindow with the following:

	void paint (Graphics& g)
		Rectangle<int> iPadBounds = getPeer()->getBounds();
		if  ( (iPadBounds.getWidth()!=getWidth()) && (iPadBounds.getHeight()!=getHeight()) )
		g.fillAll (Colours::lightgrey);


from your main top level DocumentWindow… getPeer()->getBounds() appears to give you the updated width and height of the ipad screen. So you compare it against your DocumentWindow’s width and height. If it’s mismatched, the screen has been rotated so call getPeer()->handleScreenSizeChange() after which everything here seems to work.

whaddap jules! it’s been a long time! I forgot my old password, and the forum is going to a dead email account.

Hey, good to hear from you again! (Let me know if you want me to fix your old forum account, BTW)

Just started looking at this issue too. Has anyone got any further?

I have been playing around with this. I followed steps listed by Modulr_One. I looked at the additions in then added these to the my working copy of the latest juce tip. Instead of just allowing rotation for home button on left and right only, I just return YES (for all positions). The content component of the main window does rotate correctly. However, the menu popup menus seem to popup in random postions of the screen. Showing modal dialogs seems to show half the window so there won’t be a way of controlling the app again, since I can’t close the dialog window :cry:.

In the constructor of UIViewComponentPeer, it seems the UIViewController that handles the rotation is only instantiated if there is no view to attach to (ie. isSharedWindow is false). Is this because the rotation is governed by view that will be attached to? Could someone point me in the right direction regarding where I can find an overview of the design of GUI handling of juce so that I can play with this a bit more.

I must say Juce never ceases to amaze me!

Well, I thought I’d spend a few minutes adding display rotation support… and that damn thing ended up taking me all day! Seems to be working now though - have a look in the Desktop class if you want to set it to rotate to specific orientations.