iOS: Initial interface orientation[UIInterfaceOrientation] being ignored in plist
Asked Answered
P

2

4

I'm trying to set the initial orientation for my app to be UIInterfaceOrientationLandscapeLeft

I cant get

'Initial interface orientation'[UIInterfaceOrientation]

to override the first item in array of

'Supported interface orientations'[UISupportedInterfaceOrientations]

I noticed an iphone app always starts with 'Portrait (bottom home button)'.and the array is:

'Supported interface orientations'[UISupportedInterfaceOrientations]

Portrait (bottom home button)

Landscape (left home button)

Landscape (right home button)

Which is as expected.

If I turn PORTRAIT HOME BOTTOM button on Summary page OFF THEN BACK ON then the order of the array changes and Portrait (bottom home button) moves to the bottom.

Landscape (left home button)

Landscape (right home button)

Portrait (bottom home button)

and when I run the app it now starts in Landscape (left home button) as this is now top of the list. Which is fine

BUT

when I add

'Initial interface orientation'[UIInterfaceOrientation]

and set it to

Landscape (right home button)

Its ignored and the first item in the array is used instead

Landscape (left home button)

I checked shouldAutorotateToInterfaceOrientation and it only blocks Portrait upside down

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

I also added debug code

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(interfaceOrientation == UIInterfaceOrientationPortrait){
        NSLog(@"shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait");
    }else if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
            NSLog(@"shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown");
    }else  if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
            NSLog(@"shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft");
    }else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight){
        NSLog(@"shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight");
    }else {
        NSLog(@"shouldAutorotateToInterfaceOrientation:UNKNOWN");
    }

    return YES;
}

and I get

 shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight
 shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight
 shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight
 shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight
 shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight
 shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft
 shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft

so you can see it does try an use

'Initial interface orientation'[UIInterfaceOrientation]

and set it to

Landscape (right home button)

but then it switches back to the first item in the array is used instead

Landscape (left home button)

am I doing something wrong? This is a simple SINGLE VIEW Xcode Template project... just add the debug code.

Potential answered 15/2, 2012 at 17:30 Comment(1)
just checked another project and they delete all orientations in the array except the one they want. Then set Initial to same value. Wont work on ipad, should support them all AND set inital.Potential
I
16

Despite the documentation, UIInterfaceOrientation is ignored. Use only UISupportedInterfaceOrientations. To specify which one you prefer to launch into, make it the first one listed in UISupportedInterfaceOrientations.

It is then up to your individual view controllers to rule out any orientations they refuse to adopt.

Intense answered 16/10, 2012 at 2:1 Comment(0)
I
1

Initial Interface Orientation did not worked for me. I just changed the sequence in supported interface orientation and it worked. enter image description here

Iodous answered 13/5, 2016 at 13:8 Comment(1)
Absolutely correct! Plus: the order of the items is important here!Deva

© 2022 - 2024 — McMap. All rights reserved.