Launching application in landscape orientation for

2020-02-02 13:12发布

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

标签: iphone ipad
4条回答
劳资没心,怎么记你
2楼-- · 2020-02-02 13:26

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.

查看更多
该账号已被封号
3楼-- · 2020-02-02 13:27

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.

查看更多
家丑人穷心不美
4楼-- · 2020-02-02 13:33

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!

查看更多
贪生不怕死
5楼-- · 2020-02-02 13:35

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?

查看更多
登录 后发表回答