<p>Please note that this question is from 2008 and now is of only historic interest.</p>

<hr>

<p>What's the best way to create an iPhone application that runs in landscape mode from the start, regardless of the position of the device?</p>

<p>Both programmatically and using the Interface Builder.</p>

[{'answer_id': 36884, 'author': 'Michael Pryor', 'author_id': 245, 'author_profile': 'https://Stackoverflow.com/users/245', 'pm_score': 5, 'selected': False, 'text': '<p>From the Apple Dev Site:</p>\n\n<blockquote>\n  <p>To start your application in landscape\n  mode so that the status bar is in the\n  appropriate position immediately, edit\n  your Info.plist file to add the\n  UIInterfaceOrientation key with the\n  appropriate value\n  (UIInterfaceOrientationLandscapeRight\n  or\n  UIInterfaceOrientationLandscapeLeft),\n  as shown in Listing 2.</p>\n  \n  <p>Listing 2: Starting your application\n  in landscape mode</p>\n\n<pre><code>&lt;key&gt;UIInterfaceOrientation&lt;/key&gt;\n&lt;string&gt;UIInterfaceOrientationLandscapeRight&lt;/string&gt;\n</code></pre>\n</blockquote>\n'}, {'answer_id': 36899, 'author': 'Sören Kuklau', 'author_id': 1600, 'author_profile': 'https://Stackoverflow.com/users/1600', 'pm_score': 3, 'selected': False, 'text': '<p>sasb\'s and michaelpryor\'s answer appears to be correct, but if it\'s not working for you, try this alternative:</p>\n\n<pre><code>- (void)applicationDidFinishLaunchingUIApplication *)application {\n    application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;\n}\n</code></pre>\n\n<p>Or this one:</p>\n\n<pre><code>[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];\n</code></pre>\n\n<p>Or this one:</p>\n\n<pre><code>[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];\n</code></pre>\n\n<p>You may also have to call <code>window makeKeyAndVisible;</code> first.</p>\n\n<p>A few links: <a href="http://www.iphonedevsdk.com/forum/iphone-sdk-development/1664-developing-landscape-mode.html" rel="nofollow noreferrer">Developing in landscape mode</a>, <a href="http://discussions.apple.com/thread.jspa?threadID=1454154&amp;tstart=135" rel="nofollow noreferrer">iPhone SDK: How to force Landscape mode only?</a></p>\n\n<p>@Robert: please refer to <a href="https://stackoverflow.com/questions/23482/the-iphone-sdk-nda-and-stack-overflow">The iPhone SDK, NDA, and Stack Overflow</a>.</p>\n'}, {'answer_id': 44876, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>The latest iPhone OS Programming Guide has a full section on this, with sample code. I am sure this is a recent addition, so maybe you missed it. It explains all the conditions you have to comply with; basically...</p>\n\n<ul>\n<li>set the Info.plist properties (this changes the position of the status bar, but not the view)</li>\n<li>rotate your view manually around its center, on either your UIViewController viewDidLoad: method or your applicationDidFinishLaunching: method or implement auto rotation ("Autoresizing behaviors", page 124)</li>\n</ul>\n\n<p>Look for "Launching in Landscape Mode", page 102.</p>\n'}, {'answer_id': 1773197, 'author': 'samvermette', 'author_id': 87158, 'author_profile': 'https://Stackoverflow.com/users/87158', 'pm_score': 3, 'selected': False, 'text': '<p>First I set in info.plist</p>\n\n<pre><code>&lt;key&gt;UIInterfaceOrientation&lt;/key&gt;\n&lt;string&gt;UIInterfaceOrientationLandscapeRight&lt;/string&gt;\n</code></pre>\n\n<p>then I put this code in applicationDidFinishLaunching:</p>\n\n<pre><code>CGAffineTransform rotate = CGAffineTransformMakeRotation(1.57079633);\n[window setTransform:rotate];\n\nCGRect contentRect = CGRectMake(0, 0, 480, 320); \nwindow.bounds = contentRect; \n[window setCenter:CGPointMake(160.0f, 240.0f)]; \n</code></pre>\n\n<p>This way I can work on the view in Interface Builder in landscape mode.</p>\n'}, {'answer_id': 2530953, 'author': 'Fattie', 'author_id': 294884, 'author_profile': 'https://Stackoverflow.com/users/294884', 'pm_score': 7, 'selected': True, 'text': '<h1>Historic answer only. Spectacularly out of date.</h1>\n<p>Please note that this answer is now hugely out of date/</p>\n<p>This answer is <strong>only a historical curiosity</strong>.</p>\n<hr />\n<p>Exciting news! As discovered by Andrew below, this problem has been fixed by Apple in 4.0+.</p>\n<p>It would appear it is NO longer necessary to force the size of the view on every view, and the specific serious problem of landscape &quot;only working the first time&quot; has been resolved.</p>\n<p>As of April 2011, it is not possible to test or even build anything below 4.0, so the question is purely a historic curiosity.  It\'s incredible how much trouble it caused developers for so long!</p>\n<hr />\n<p>Here is the original discussion and solution. This is utterly irrelevant now, as these systems are not even operable.</p>\n<hr />\n<p>It is EXTREMELY DIFFICULT to make this work fully -- there are at least three problems/bugs at play.</p>\n<p>try this .. <a href="http://www.iphonedevsdk.com/forum/iphone-sdk-development/7366-interface-builder-landscape-design.html#post186977" rel="noreferrer">interface builder landscape design</a></p>\n<p>Note in particular that where it says <em>&quot;and you need to use shouldAutorotateToInterfaceOrientation properly everywhere&quot;</em> it means everywhere, all your fullscreen views.</p>\n<p>Hope it helps in this nightmare!</p>\n<p>An important reminder of the ADDITIONAL well-known problem at hand here: if you are trying to swap between <em><strong>MORE THAN ONE</strong></em> view (all landscape), <em><strong>IT SIMPLY DOES NOT WORK</strong></em>.  It is essential to remember this or you will waste days on the problem. It is literally NOT POSSIBLE. It is the biggest open, known, bug on the iOS platform. There is literally no way to make the hardware make the second view you load, be landscape. The annoying but simple workaround, and what you must do, is have a trivial master UIViewController that does nothing but sit there and let you swap between your views.</p>\n<p>In other words, in iOS because of a major know bug:</p>\n<pre><code>[window addSubview:happyThing.view];\n[window makeKeyAndVisible];\n</code></pre>\n<p><em><strong>You can do that only once</strong></em>. Later, if you try to remove happyThing.view, and instead put in there newThing.view, IT DOES NOT WORK - AND THAT\'S THAT. The machine will never rotate the view to landscape. There is no trick fix, even Apple cannot make it work. The workaround you must adopt is having an overall UIViewController that simply sits there and just holds your various views (happyThing, newThing, etc). Hope it helps!</p>\n'}, {'answer_id': 2787997, 'author': 'IlDan', 'author_id': 103529, 'author_profile': 'https://Stackoverflow.com/users/103529', 'pm_score': 5, 'selected': False, 'text': '<p><em>Summary and integration from all the posts, after testing it myself; check the update for 4.x, 5.x below.</em></p>\n\n<p>As of 3.2 you cannot change the orientation of a running application from code.</p>\n\n<p>But you can start an application with a fixed orientation, although doing so this is not straightforward. </p>\n\n<p>Try with this recipe:</p>\n\n<ol>\n<li>set your orientation to <code>UISupportedInterfaceOrientations</code> in the <code>Info.plist</code> file</li>\n<li>in your window define a 480x320 "base view controller". Every other view will be added as a subview to its view.</li>\n<li>in all view controllers set up the <code>shouldAutorotateToInterfaceOrientation:</code> method (to return the same value you defined in the plist, of course)</li>\n<li><p>in all view controllers set a background view with </p>\n\n<p><code>self.view.frame = CGRectMake(0, 0, 480, 320)</code> </p>\n\n<p>in the <code>viewDidLoad</code> method.</p></li>\n</ol>\n\n<p><strong>Update (iOS 4.x, 5.x)</strong>: the Apple iOS App Programming Guide has a "Launching in Landscape Mode" paragraph in the "Advanced App Tricks" chapter.</p>\n\n<p>References:</p>\n\n<ul>\n<li><a href="http://www.iphonedevsdk.com/forum/iphone-sdk-development/7366-interface-builder-landscape-design.html#post186977" rel="noreferrer">interface builder landscape design</a></li>\n<li><a href="http://www.iphonedevsdk.com/forum/iphone-sdk-development/7366-interface-builder-landscape-design.html#post190014" rel="noreferrer">interface builder landscape design-1</a></li>\n</ul>\n'}, {'answer_id': 4290617, 'author': 'Arlen Anderson', 'author_id': 247151, 'author_profile': 'https://Stackoverflow.com/users/247151', 'pm_score': 3, 'selected': False, 'text': "<p>I'm surprised no one has come up with this answer yet:</p>\n\n<p>In all my tests when a dismissing a modal view controller the parent view controller's preferred orientation set in <code>shouldAutorotateToInterfaceOrientation</code> is honored even when part of a UINavigationController. So the solution to this is simple:</p>\n\n<p>Create a dummy UIViewController with a UIImageView for a background. Set the image to the default.png image your app uses on startup.</p>\n\n<p>When <code>viewWillAppear</code> gets called in your root view controller, just present the dummy view controller without animation.</p>\n\n<p>when <code>viewDidAppear</code> gets called in your dummy view controller, dismiss the view controller with a nice cross dissolve animation.</p>\n\n<p>Not only does this work, but it looks good! BTW, just for clarification i do the root view controller's <code>viewWillAppear</code> like this:</p>\n\n<pre><code>- (void)viewWillAppear:(BOOL)animated\n{\n if ( dummy != nil ) {\n  [dummy setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];\n  [self presentModalViewController:dummy animated:NO];\n  [dummy release];\n  dummy = nil;\n }\n...\n}\n</code></pre>\n"}, {'answer_id': 5209365, 'author': 'nicc', 'author_id': 499901, 'author_profile': 'https://Stackoverflow.com/users/499901', 'pm_score': 2, 'selected': False, 'text': '<p>See this answer: <a href="https://stackoverflow.com/questions/2647786/landscape-mode-only-for-iphone-or-ipad/2647807#2647807">Landscape Mode ONLY for iPhone or iPad</a></p>\n\n<ol>\n<li>add orientation to plist</li>\n<li>shouldAutorotateToInterfaceOrientation = YES in all files</li>\n</ol>\n\n<p>Although if you\'re using mixed modes, you might be better off with </p>\n\n<pre><code>[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/402', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/136/']