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)shouldAutorotateToInterfaceOrientationUIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); You need to change UIInterfaceOrientationPortrait to either LandscapeLeft or LandscapeRight. Hope that helped!
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
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)shouldAutorotateToInterfaceOrientationUIInterfaceOrientation)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)
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.
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.
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.
Ahh...more stuff I should know - sorry if I gave any wrong information; I'm not really an experienced dev ...but I will be .
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! I feel for ya buddy! Thought you already had one.
Not the main app view? 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
I'd use both. Pet peeve: if you set it one way and one way only, you end up making it a wee bit uncomfortable for iTouch or iPhone users to play the game (depending on which way you set landscape orientation). Remember, the headphone jack is in different places on the iTouch and the iPhone. When in portrait (with home button on the lower portion), on iTouch the jack is on the lower right hand side, and on iPhone the lower left hand side. If you don't allow for screen orientation toggle when in landscape mode, inevitably the jack will be on the lower portion of one or the other style of device. This is NOT comfortable at all. You've got to keep BOTH style of hardware in mind, as doing so will keep the total amount of end users in mind. And, y'know...we kinda appreciate those little things.
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.
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."
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.