Блокировка входа в игровой центр в ландшафте только в я OS 6
Когда игровой центр загружен, его ориентация по умолчанию - портрет.
Чтобы заблокировать его в ландшафтном режиме, добавлена категория.
@implementation GKMatchmakerViewController (LandscapeOnly)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate {
return NO;
}
@end
Он работает отлично в iOS 6. Но в iOS6 он показывает ошибку.
Завершение приложения из-за неперехваченного исключения "UIApplicationInvalidInterfaceOrientation", причина: "Поддерживаемые ориентации не имеют общей ориентации с приложением, а shouldAutorotate возвращает YES"
Пожалуйста, объясните решение.
Ответы
Ответ 1
Наконец, я избежал краха, следуя обходному решению, упомянутому в Apple iOS 6 примечания к выпуску.
Обход проблемы:
1.Apps should provide the delegate method
application:supportedIntefaceOrientationsForWindow and ensure that portrait is one of the returned mask values.
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
2. Когда задействуется UIBNavigationController (или UIViewController), подклассифицируйте UINavigationController/UIViewController и переопределите supportInterfaceOrientations.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
и
In buid summary supported orientations selected landscape right and landscape left.
Теперь игровой центр работает без сбоев.
Ответ 2
Придется добавить 1 маленькую вещь. Борясь с этой глупой проблемой около 2 дней. Если выше не помогает, и у вас есть UINavigationController invovled (и вы уже выполнили его подкласс), вам понадобится следующее (в appDelegate):
[window setRootViewController:navigationController]; // use this
// instead of [self.window addSubview:navigationController.view];
thanx 2 http://grembe.wordpress.com/2012/09/19/here-is-what-i/