I was looking for the answer to this question, but could not find anything that solved my problem.
So, here is the problem: I have a custom UINavigationController, when creating its method supportedInterfaceOrientationsis called on rootViewController (only portrait is supported). But when you click another ViewController on the stack, this method is not called when the ViewController is pressed (it supports everything except the inverted one).
I solved it by calling [self supportedInterfaceOrientations]in the method viewDidLoad, but I think this is not a very good way to solve the problem.
I hope you will help me in this matter.
Here, my code is 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;
}
}
, johnMa , , , ( , , ).
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 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];
}
}
}
, .