View Full Version : Still learning- how do you force landscape?
wastedyuthe
01-28-2009, 08:07 AM
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.
Mew2468
01-28-2009, 08:48 AM
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!
wastedyuthe
01-28-2009, 08:59 AM
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 :)
Mew2468
01-28-2009, 09:07 AM
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)
wastedyuthe
01-28-2009, 09:18 AM
...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.
Diablohead
01-28-2009, 10:58 AM
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.
Hippieman
01-28-2009, 02:21 PM
Don't make a game upside down!
Use the YouTube or Movie player as your guide.
wastedyuthe
01-28-2009, 03:08 PM
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.
InsertWittyName
01-28-2009, 03:37 PM
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.
wastedyuthe
01-28-2009, 03:50 PM
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 :rolleyes: )
[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.
Mew2468
01-28-2009, 05:02 PM
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 :rolleyes: )
[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.
Ahh...more stuff I should know - sorry if I gave any wrong information; I'm not really an experienced dev :rolleyes:...but I will be :D.
Rocketman919
01-28-2009, 06:21 PM
damn i need to get an intel mac soon...
wastedyuthe
01-29-2009, 06:31 AM
The property list is very helpful. So far, I have been able to force landscape, remove the bar at the top of the window which shows the time and battery etc, and even managed to remove the reflection from the apps Home screen icon. Groovy!
http://i95.photobucket.com/albums/l125/wastedyuthe/plist.png
damn i need to get an intel mac soon...
I feel for ya buddy! Thought you already had one.
cgriffin
01-29-2009, 11:40 AM
I have a need for landscape orientation as well. Except I need it for a view that isn't the main app view. Searching the web tells me that I need to rotate the view myself. The problem is that no matter what I set the 'origin' to I can't get the view to rotate correctly, it always rotates off the screen. If anyone has an example on how to do this I would appreciate it greatly.
Thanks,
Chris
InsertWittyName
01-29-2009, 03:04 PM
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?
You cannot override the property list value, no.
You can however call the function to force an orientation in your applicationDidFinishLaunching or similar method, a quick Google for 'UIInterfaceOrientation force landscape' will give you a few options.
To actually save the user's preferences from one launch to the next Google for 'NSUserDefaults tutorial'.
Half the battle of learning is know the key words on what to search for.
wastedyuthe
01-29-2009, 03:24 PM
You cannot override the property list value, no.
You can however...
Thank you very much. You are most helpful. You are right about knowing the keywords. I am sure It'll all be a bit clearer when I get my book (hopefully next week). I'm not doing too badly though- done my first app, copying a simple calculator app from a podcast. But I changed it to add a nice background picture of a demon embracing a naked lady, and I changed a button so you have to tap her bum (which turns red when you do so) to get the sum to appear. Hehe!
I have been working on the title screen of my first proper game today (which will be a simple 2D affair), and am looking forward to getting stuck in.
[edit] Here's yet another way to do it (from a Google search):
"Open up your App Delegate M file.
Put This:
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
Into the:
- (void)applicationDidFinishLaunchingUIApplication *)application {
Method."
Mew2468
01-29-2009, 10:23 PM
Thank you very much. You are most helpful. You are right about knowing the keywords. I am sure It'll all be a bit clearer when I get my book (hopefully next week). I'm not doing too badly though- done my first app, copying a simple calculator app from a podcast. But I changed it to add a nice background picture of a demon embracing a naked lady, and I changed a button so you have to tap her bum (which turns red when you do so) to get the sum to appear. Hehe!
I have been working on the title screen of my first proper game today (which will be a simple 2D affair), and am looking forward to getting stuck in.
[edit] Here's yet another way to do it (from a Google search):
"Open up your App Delegate M file.
Put This:
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
Into the:
- (void)applicationDidFinishLaunchingUIApplication *)application {
Method."
Can't wait to see your final products :)!
wastedyuthe
01-30-2009, 05:37 AM
Can't wait to see your final products :)!
Thanks, but it's going to be a bit of a wait. Drawing the Main Menu screen graphics is one thing (which I finished last night- looking groovy!)- programming the game mechanics is another, as well as all the animation I'll have to draw. Luckily I have already been writing my own instrumental music for the past couple of years with GarageBand, so I'll just stick some of my already-created music in there. That'll save a bit of work.
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.