★ TouchArcade needs your help. Click here to support us on Patreon.

Still learning- how do you force landscape?

01-28-2009, 09:07 AM
#1
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
Still learning- how do you force landscape?

Sorry- I am waiting for my book to arrive on learning ObjC and have been learning what I can from websites and podcasts, so I don't know all the ins and outs yet. I have done a couple of simple apps so far, but can't find any sample code which actually tells you how to force landscape mode instead of portrait. Could someone tell me please?
Thank you.
01-28-2009, 09:48 AM
#2
Joined: Oct 2008
Location: Vancouver, BC
Posts: 1,652
Quote:
Originally Posted by wastedyuthe View Post
Sorry- I am waiting for my book to arrive on learning ObjC and have been learning what I can from websites and podcasts, so I don't know all the ins and outs yet. I have done a couple of simple apps so far, but can't find any sample code which actually tells you how to force landscape mode instead of portrait. Could someone tell me please?
Thank you.
You have to change some code somewhere from UIOrientationPortrait to UIOrientationLandscapeLeft or UIOrientationLandscapeRight.

That's all I really remember :).

EDIT: Okay, I looked at one of my random useless apps, and in the (YourProjectName)ViewController.m, you need to change some code...

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIIn terfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);


You need to change UIInterfaceOrientationPortrait to either LandscapeLeft or LandscapeRight.

Hope that helped!

 /l、
(゚、
 l、 ~ヽ
 じしf_, )ノ Inconspicuous Group Cat?

Last edited by Mew2468; 01-28-2009 at 09:52 AM.

01-28-2009, 09:59 AM
#3
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
Wow! Thanks a bunch! I will look into that. I have an idea for a first app, and I needed it landscape.
I really want to add an option as to which side you want it facing (left or right). But by default, what is the general consensus? Is left or right facing preferable?

[edit] Yes, tried the above "return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);" and it works a treat. Thank you

Last edited by wastedyuthe; 01-28-2009 at 10:04 AM.
01-28-2009, 10:07 AM
#4
Joined: Oct 2008
Location: Vancouver, BC
Posts: 1,652
Quote:
Originally Posted by wastedyuthe View Post
Wow! Thanks a bunch! I will look into that. I have an idea for a first app, and I needed it landscape.
I really want to add an option as to which side you want it facing (left or right). But by default, what is the general consensus? Is left or right facing preferable?
Most games use left (which is home button on the right), but a couple of them use right (such as Trace), so its really up to you to decide. You can, although, code the orientation thing like this...

*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIIn terfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

And that way, they can use either orientation. Unless you want it to only work one way. I'd go with LandscapeLeft.

(The space between UIIn and terface isn't intentional...the font did it XD - it should just be UIInterfaceOrientation)

 /l、
(゚、
 l、 ~ヽ
 じしf_, )ノ Inconspicuous Group Cat?

Last edited by Mew2468; 01-28-2009 at 10:10 AM.
01-28-2009, 10:18 AM
#5
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
Quote:
Originally Posted by Mew2468 View Post
...And that way, they can use either orientation. Unless you want it to only work one way. I'd go with LandscapeLeft.
I put both in there as you did, and it starts off to the right (with the Home button on the left) in the simulator. And if I turn left a couple of times to left landscape, the picture doesn't orientate to the right way up (as it does if I'd just say "return YES;" in that same method (which orientates it to which ever way you hold it up). So even though both are listed, it only shows it the right way up when in Right landscape. Is that right? Do I need to tell it to swap orientation when turning to the left?

[edit] I noticed if you swap them so Right is listed before Left, the app starts off with left orientation, so it starts with which ever is listed last.

Last edited by wastedyuthe; 01-28-2009 at 10:25 AM.
01-28-2009, 11:58 AM
#6
Joined: Jan 2009
Posts: 1,553
Information like this is extremely handy and you would think it would be noted somewhere online easy to find, it might be worth noting down stuff like this as I develop for all to read.

3D modelling, design and sequential artist / GameCenter ID: Diab
01-28-2009, 03:21 PM
#7
Joined: Nov 2008
Location: San Francisco
Posts: 430
Don't make a game upside down!

Use the YouTube or Movie player as your guide.

I've made a lot of games. You've played them.
01-28-2009, 04:08 PM
#8
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
Quote:
Originally Posted by Hippieman View Post
Don't make a game upside down!

Use the YouTube or Movie player as your guide.
I hear ya. Landscape left it is

[edit] read later posts- should be LandscapeRight.

Last edited by wastedyuthe; 01-29-2009 at 07:44 AM.
01-28-2009, 04:37 PM
#9
shouldAutorotateToInterfaceOrientation only allows the view to rotate, it doesn't force a landscape orientation.

To force a landscape orientation add a new entry to your Info.plist file with a key of UIInterfaceOrientation and a value of UIInterfaceOrientationLandscapeLeft or UIInterfaceOrientationLandscapeRight.

Didev Studios || Twitter || YouTube || Facebook
Releases
GeoSnake || Bugz || Review Scraper (Open Source)
01-28-2009, 04:50 PM
#10
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
Quote:
Originally Posted by InsertWittyName View Post
shouldAutorotateToInterfaceOrientation only allows the view to rotate, it doesn't force a landscape orientation.

To force a landscape orientation add a new entry to your Info.plist file with a key of UIInterfaceOrientation and a value of UIInterfaceOrientationLandscapeLeft or UIInterfaceOrientationLandscapeRight.
Ahh! Thanks for that. This property list command works together with the 'shouldautorotate...' command I see. Interesting.

But say I want to add an option in my games settings, so the user can choose which way they want- left landscape or right landscape. There is no way for that property list command to be over-ridden is there?

(perhaps I am getting in way over my head here )

[edit] "Most games use left (which is home button on the right)"
I set it to LandscapeLeft in the property list, and the Home button is on the left not the right. So, if people prefer the Home button on the right, then I should set it to LandscapeRight.

Last edited by wastedyuthe; 01-28-2009 at 04:59 PM.