8

I am developing an app for iOS 5, which have to run in landscape mode. My problem is that I cannot get it to flip initially.

I have tried the adding "Initial interface orientation" set to "Landscape (right home button)" and adding the following method to my view controller:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

I can wrap my head around how it is supposed to work. (I found the code here)

I am also wondering how to use the "Supported Device Orientation" available in the Xcode 4.2 project setup, it does not seem to do anything.

I have been looking around the website and have not been able to find an example that solves my problem.

Thank you.

5 Answers5

15

In your application’s Info.plist file, add the UIInterfaceOrientation key and set its value to the landscape mode. For landscape orientations, you can set the value of this key to UIInterfaceOrientationLandscapeLeft or UIInterfaceOrientationLandscapeRight.

Lay out your views in landscape mode and make sure that their autoresizing options are set correctly.

Override your view controller’s shouldAutorotateToInterfaceOrientation: method and return YES only for the desired landscape orientation and NO for portrait orientations.

Saurabh
  • 22,743
  • 12
  • 84
  • 133
  • Thank you. I did do as you described. I have more then one subview and found out I had to override the method on all controllers before I got it to work. –  Jan 20 '12 at 11:22
  • if in your info.plist you put the UIInterfaceOrientationLandscapeRight above the other landscapes then you can start your app on landscape – Avi Cohen Nov 16 '14 at 08:39
11

use the following in appDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

also set the required orientations in

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

//Here are some iOS6 apis, used to handle orientations.
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0) 
- (NSUInteger)supportedInterfaceOrientations - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
vishy
  • 3,241
  • 1
  • 20
  • 25
  • shouldAutorotateToInterfaceOrientation: not called help me its appreciated – Jignesh B Oct 02 '13 at 09:28
  • @JigPatel use some of these new methods in ios6 `- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0) - (NSUInteger)supportedInterfaceOrientations - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation` – vishy Oct 02 '13 at 16:26
1

When you click on your project's name in XCode and select your target under TARGETS, under Summary tab there's a visual representation of the supported device orientation settings. That was how I managed to do it.

aslı
  • 8,740
  • 10
  • 59
  • 80
0

i think if you at the supported interface orientations in the project plist it will work. just add a new line called "Supported interface orientations" and make it of array type and add 2 items for each of teh landsape views u want. havent tested this just a quick guess

glogic
  • 4,042
  • 3
  • 28
  • 44
-2

Try this this will help you, write this code in you viewdidload.

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
Dipen Chudasama
  • 3,063
  • 21
  • 42