6

Facing one issue with launching application in landscape orientation for IPad. I have developed IPhone application which later I ported to IPad.

I have made setting regarding orientation in info.plist

[ UISupportedInterfaceOrientations~ipad ] to support all orientation UIInterfaceOrientationPortrait , UIInterfaceOrientationPortraitUpsideDown , UIInterfaceOrientationLandscapeLeft , UIInterfaceOrientationLandscapeRight.

but when I start IPad application in the landscape mode, it always start in the potrait mode.

Along this

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{ return YES; }

help me, if I am missing something with this..

Thanks,

Sagar

Sagar...
  • 1,062
  • 3
  • 15
  • 35
  • If you are defining support for all orientation then your views will be in the same mode as your device. i.e If your device is in portrait mode then your view will be displayed in portrait mode. Changing the device orientation will also change the view orientation as well. – Jim Jun 01 '10 at 06:12
  • Thanks Jim for reply.. but I am starting application when the orientation is in landscape mode... it still start in portrait mode ( i.e as per direction of home button ). I need to achieve the proper orientation in the beginning as need to show landscape screen or portrait screen. – Sagar... Jun 02 '10 at 05:40

4 Answers4

10

here's something I also discovered: setting the initial interface orientation in your info.plist is being ignored if you have Supported interface orientations set up with another orientation in the first slot! Put your initial orientation there as well - and the simulator will launch correctly, as will the app. this drove me nuts for a long time!

jhhl
  • 161
  • 2
  • 8
9

Put UISupportedInterfaceOrientations into your -Info.plist, with a setting for each orientation you support. This is used to see which orientation the app can start in. From there onwards it will ask your view controllers.

5

Sagar - I had the same issue but was able to resolve it.

Like yours, my app started as an iPhone app which I "upgraded" to a Universal app using the XCode wizard. I noticed that when running on the actual iPad, starting in landscape, the app would start in Portrait, then maybe rotate to Landscape. On the simulator, starting in landscape, the app would start in Landscape, then the simulator would rotate to Portrait.

On the iPad, my app is a split-view app with TabBarControllers on left and right. Each tab is a view controller that returns YES to shouldAutoRotateToInterfaceOrientation.

I noticed that a brand-new wizard-generated, simple-case with a splitviewcontroller, Universal app didn't have this problem.

The difference I found between my app and the simple-case was that I wasn't adding my splitview-controller's view to the app window in applicationDidFinishLaunchingWithOptions. Instead I was showing a "loading" view at this stage, then later when an initialization thread completed I'd add my splitviewcontroller's view (and hide the "loading" view).

When I added my splitviewcontroller's view to the app window during the call to applicationDidFinishLaunchingWithOptions everything started working fine.

There must be some magic that happens on return from applicationDidFinishLaunchingWithOptions???

Is your app similar to mine in that it isn't adding the main view controller's view to the window during applicationDidFinishLaunchingWithOptions?

TomSwift
  • 39,369
  • 12
  • 121
  • 149
  • Hi TomSwift. Thanks for reply.. I have implemented same way,as you have described. in applicationDidFinishLaunchingWithOptions I am not adding main window / infact I am adding splash screen and after that splitview is added. – Sagar... Jun 07 '10 at 06:28
  • So what happens if you add the main window instead of the splash screen? Does it fix itself? – TomSwift Jun 10 '10 at 04:17
  • See.. it seems solution for this is in applicationdidfinishlauching let the start default UI [ in my case splash scree ] and after that detect the orientation and do the view rendering.... – Sagar... Jun 14 '10 at 14:02
  • Works like a charm ... on my simulator so far. Gonna try on real device later. – iwat Oct 05 '11 at 04:50
1

As pointed out in a number of posts, you must set up the info.plist with both the supported and the initial interface orientations. However, the bigger issue is when does the initial orientation become effective? The answer is NOT when your view controller receives the "viewDidLoad" message. I found that on the iPad-1, running iOS 5.0, the requested initial orientation becomes effective only after several "shouldAutorotateToInterfaceOrientation" messages are received.(This message passes the UIInterfaceOrientation parameter to the receiver.) Furthermore, even if the orientation says it is in Landscape mode, it may not be! The only way I found to be sure that the view is in Landscape mode is to test that the view height is less than the view width. The strategy that worked for me was to lay out the subViews I wanted when the "viewDidLoad" message was received but to delay actually adding those subViews to the view until the controller received a valid "shouldAutorotate.." message with the orientation set to Landscape mode. The code looks something like:

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations

// N.B. Even when the interface orientation indicates landscape mode
// this may not really be true. So we insure this is so by testing
// that the height of the view is less than the width
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
    interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
    CGRect viewBounds = [[self view] bounds];
    if ( viewBounds.size.height < viewBounds.size.width )
        [self addMySubViews];
    return YES;   
}
else
    return NO;
}

Apple has just released iOS 5.1, so this behavior may have changed. But I expect the code that is here should still work.

vikmalhotra
  • 9,981
  • 20
  • 97
  • 137
jglipham
  • 11
  • 1