supportedInterfaceOrientations nie są wywoływane w systemie iOS 7
Szukałem odpowiedzi na to pytanie, ale nie mogłem znaleźć niczego, co rozwiązałoby mój problem.
Oto problem: mam niestandardowy kontroler UINavigationController podczas tworzenia gosupportedInterfaceOrientations
metoda jest wywoływana w rootViewController (obsługuje tylko portret). Ale podczas pchania innego kontrolera ViewController na stos ta metoda nie jest wywoływana na pchniętym kontrolerze ViewController (obsługuje wszystkie, ale do góry nogami).
Rozwiązałem to, dzwoniąc[self supportedInterfaceOrientations]
wviewDidLoad
-metoda, ale myślę, że to nie jest dobry sposób na rozwiązanie problemu.
Mam nadzieję, że możesz mi pomóc w tej sprawie.
Oto mój kod zaimplementowany w drugim viewControllerze.
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[[[UIApplication sharedApplication] delegate] setGlobalOrientationMask:UIInterfaceOrientationMaskAllButUpsideDown];
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
[[[UIApplication sharedApplication] delegate] setGlobalOrientationMask:UIInterfaceOrientationMaskAll];
return UIInterfaceOrientationMaskAll;
}
}
Myślę, że rozwiązanie z johnMa powinno działać dobrze dla większości aplikacji, ale w moim przypadku, myślę, że jest szczególny problem, ale sam go rozwiązałem (nie jestem pewien, czy jest dobry, ale działa).
Zaimplementowałem- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
metoda na moim delegatorze navigationController.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (DEF_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) {
if ([viewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
[viewController supportedInterfaceOrientations];
}
}
}
Mam nadzieję, że pomoże to innym w rozwiązaniu tego samego problemu.