3

Hi I was checking the orientations changes of iOS6 and I made everything work fine except one thing. There is no way to start the app on landscape.

How can I do to start the app on landscape? I found this How to force a UIViewController to Portrait orientation in iOS 6 but that's not working, the app ALWAYS start in portrait and I needed to start it on landscape...

When I go to an other view and then go back to the "initial view" it is on landscape! But when the app starts it's on portrait...

Thank you!!

----------------------------- UPDATE -------------------------------

This is how I'm loading from the app delegate the main view:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
myViewController = [[myViewController alloc] init];

self.navController = [[UINavigationController alloc] initWithRootViewController:myViewController] ;

[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];

----------------------------- UPDATE 2------------------------------ I made it work, I changed the previous code for:

self.navController = [[UINavigationController alloc] init] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
[navController presentViewController:myViewController animated:NO completion:NULL];

I hope this is useful for someone else!

Community
  • 1
  • 1
Andres
  • 11,439
  • 12
  • 48
  • 87

3 Answers3

0

Have you tried this?

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];

or

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];

This is working for me in both iOS 6 and iOS 5

I have another problem on trying to rotate the screen than I realize I was making the mistake of try to load the new screen with:

[self.navigationController presentModalViewController:controller animated:YES];

instead of:

[self.navigationController pushViewController:controller animated:YES];

the second one works but the first one wasn't doing what I expected.

jMelnik
  • 1,055
  • 2
  • 15
  • 26
  • thanks for the tips but I'm not using any of this lines in my app... this is driving me crazy... – Andres Sep 27 '12 at 18:23
  • Try the first code line. In my case I use the `setStatusBarOrientation:UIInterfaceOrientationLandscapeRight` on my app because I have to force the view to stay on Portrait when a video(that play on full screen and can be rotated) finishes on Landscape mode. – jMelnik Sep 27 '12 at 18:43
  • no useful for me... It's driving me crazy, because my app loads a view, that view is not in landscape (i need it to be landscape) after loading immediately calls an other view, when I go back the first view it's in landscape, but it doesn't starts on landscape... really odd... I'm out of ideas.. – Andres Sep 27 '12 at 20:21
  • the preferredInterfaceOrientationForPresentation it's not called on load... but when I come back to the view it is called... – Andres Sep 27 '12 at 20:25
  • Can you tell me how are you calling the first view in both cases? – jMelnik Sep 27 '12 at 20:27
  • from my app delegate:self.navController = [[UINavigationController alloc] initWithRootViewController:myViewController] ; [self.window setRootViewController:navController]; [self.window makeKeyAndVisible]; – Andres Sep 27 '12 at 21:20
0

This is how I made it work:

self.navController = [[UINavigationController alloc] init] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
[navController presentViewController:myViewController animated:NO completion:NULL];

I hope it helps someone else!

Andres
  • 11,439
  • 12
  • 48
  • 87
-1

I've been wrestling with this too - this is how I've fixed it:

In viewDidLoad:

CGRect frame = self.view.bounds;

if (frame.size.height > frame.size.width) {
    //hack to force landscape
    CGFloat holdHeight = frame.size.height;
    frame.size.height = frame.size.width;
    frame.size.width = holdHeight;
    self.view.bounds = frame;
}

But I'd prefer a better way.

Caroline
  • 4,875
  • 2
  • 31
  • 47