Я пытаюсь установить начальную ориентацию для моего приложения как 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... просто добавьте код отладки.