iOS: начальная ориентация интерфейса [UIInterfaceOrientation] игнорируется в plist

Я пытаюсь установить начальную ориентацию для моего приложения как UIInterfaceOrientationLandscapeLeft.

я не могу получить

'Initial interface orientation'[UIInterfaceOrientation]

чтобы переопределить первый элемент в массиве

'Supported interface orientations'[UISupportedInterfaceOrientations]

Я заметил, что приложение для iphone всегда начинается с «Портрет (нижняя домашняя кнопка)». И массив:

'Supported interface orientations'[UISupportedInterfaceOrientations]

Portrait (bottom home button)

Landscape (left home button)

Landscape (right home button)

Что, как и ожидалось.

Если я отключу кнопку PORTRAIT HOME BOTTOM на странице сводки, а затем снова включу, то порядок массива изменится, и Portrait (нижняя домашняя кнопка) переместится вниз.

Landscape (left home button)

Landscape (right home button)

Portrait (bottom home button)

и когда я запускаю приложение, оно теперь запускается в альбомной ориентации (левая кнопка «Домой»), так как теперь оно находится в верхней части списка. что хорошо

НО

когда я добавляю

'Initial interface orientation'[UIInterfaceOrientation]

и установите его на

Landscape (right home button)

Он игнорируется, и вместо него используется первый элемент массива.

Landscape (left home button)

Я проверил shouldAutorotateToInterfaceOrientation, и он блокирует только перевернутый портрет.

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

Я также добавил код отладки

- (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;
}

и я получаю

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

так что вы можете видеть, что он пытается использовать

'Initial interface orientation'[UIInterfaceOrientation]

и установите его на

Landscape (right home button)

но затем он переключается обратно на первый элемент в массиве вместо этого используется

Landscape (left home button)

Я делаю что-то неправильно? Это простой проект шаблона SINGLE VIEW Xcode... просто добавьте код отладки.


person brian.clear    schedule 15.02.2012    source источник
comment
только что проверил другой проект, и они удаляют все ориентации в массиве, кроме той, которую они хотят. Затем установите Initial на то же значение. Не будет работать на ipad, должен поддерживать их все И установить инициализацию.   -  person brian.clear    schedule 15.02.2012


Ответы (2)


Несмотря на документацию, UIInterfaceOrientation игнорируется. Используйте только UISupportedInterfaceOrientations. Чтобы указать, какой из них вы предпочитаете запускать, сделайте его первым в списке UISupportedInterfaceOrientations.

Затем ваши отдельные контроллеры представления должны исключить любую ориентацию, которую они отказываются принимать.

person matt    schedule 16.10.2012
comment
Это исправило это и для меня. - person DJPJ; 17.07.2014

Начальная ориентация интерфейса у меня не сработала. Я просто изменил последовательность в поддерживаемой ориентации интерфейса, и это сработало. введите здесь описание изображения

person AsifHabib    schedule 13.05.2016
comment
Совершенно верно! Плюс: здесь важен порядок предметов! - person mourodrigo; 13.08.2017