PreferInterfaceOrientationForPresentation должен возвращать поддерживаемую ориентацию интерфейса
Эта ошибка не имеет смысла, так как предпочтительная ориентация UIInterfaceOrientationLandscapeRight
возвращается поддерживаемой ориентацией
//iOS6
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
Ошибка:
Завершение приложения из-за неперехваченного исключения "UIApplicationInvalidInterfaceOrientation", причина: 'preferInterfaceOrientationForPresentation должен возвращать поддерживаемый ориентация интерфейса! '
Ответы
Ответ 1
Ваш код должен выглядеть так:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
Кроме того, убедитесь, что в Info.plist
вы установили правильные ориентации для своего приложения, потому что то, что вы возвращаете из supportedInterfaceOrientations
, пересекается с Info.plist
, и если он не может найти общий, то вы получите эту ошибку.
Ответ 2
supportedInterfaceOrientations вызывается только, если shouldAutorotate установлен на YES
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
Самый простой способ для меня - установить только Info.plist
![info.plist]()
Если вам нравится поддерживать iOS 5, используйте этот код в своих контроллерах.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Ответ 3
Это неверные перечисления для supportedInterfaceOrientations
. Вам нужно использовать UIInterfaceOrientationMaskLandscapeLeft
и т.д. (отметить маску слова)
Ответ 4
из документации:
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
Обратите внимание, что правильная ориентация - "Маска"!
Вы попробовали это?