I searched for an answer to this, but couldn't find anything which solved my problem.
So here's the problem:
I have a custom UINavigationController, when creating it the supportedInterfaceOrientations
method is called on the rootViewController(only supports portrait).
But when pushing an other ViewController onto the stack this method isn't called on the pushed ViewController(supports all but upside-down).
I solved it by calling [self supportedInterfaceOrientations]
in the viewDidLoad
-method, but i think that's not a good way to solve the problem.
I hope you can help me in that matter.
Here's my code i implemented in the second viewController.
- (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;
}
}
I think the solution from johnMa should work fine for the most apps, but in my case, there's a special problem i think, but i solved it by myself now(not sure if it's a good one, but it works).
I implemented the - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
method on my navigationController-delegate.
- (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];
}
}
}
I hope this can help others with the same problem.