I created a "Single View Application" project and set all options to launch and support only landscape orientation. But the app launches with its window in portrait orientation.
Console output says that the window after application:didFinishLaunchingWithOptions:
is:
{{0, 0}, {768, 1024}}
I added a standard system button to view of ViewController to illustrate that the app is landscape and not portrait, but that the window is portrait.
Because stack overflow has white background I colored the right part gray in Photoshop so you can see it:
In application:didFinishLaunchingWithOptions:
I colored the window red. It is clearly not in landscape orientation.
I have tried all the tricks I know:
1) Info.plist contains UISupportedInterfaceOrientations key with: UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight
2) Info.plist contains UISupportedInterfaceOrientations~ipad key with: UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight
3) Info.plist contains UIInterfaceOrientation key for initial interface orientation: UIInterfaceOrientationLandscapeRight
4) Clicked on the project in Xcode and then unchecked all portrait options and only checked the landscape options:
5) AppDelegate and the ViewController both have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate {
return YES;
}
6) AppDelegate has:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Xcode created two storyboard files. I am only testing on iPad right now. One is Main_iPad.storyboard and it shows a view controller which was in portrait. But it was only a simulated interface metric. Changed to landscape and as expected no effect.
During app launch I check UIScreen bounds and it also is clearly portrait, not landscape:
CGRect screenBounds = [[UIScreen mainScreen] bounds]; // {{0, 0}, {768, 1024}}
How can I make it launch in landscape and create a window in landscape orientation?
While in interface builder click on View Controller, then in Size Inspector switch Simulated Size to Freeform (from Fixed), enter 1024 for Width and 768 for Height. It works for me.
I had a similar problem before, so maybe they're related...
I had a problem because I was creating my view programmatically in my view controller's
initWithNibName:bundle:
and for whatever reason, doing so orients the new view in portrait mode while the rest of the app is running landscape.I found two fixes for this problem. 1) Create the view using your storyboard instead of programmatically or 2) move the code to create the view from your view controller's
initWithNibName:bundle:
method and place it in the view controller's-viewDidLoad:
method like this:That was the solution for a similar problem I had. While I recognize that there's a myriad of ways that we programmers can make things not work the right way, I hope this is the answer!