我搜索了一下,但没有找到解决我的问题的答案。
问题如下: 我有一个自定义的UINavigationController,在创建它时会调用rootViewController上的“supportedInterfaceOrientations”方法(仅支持纵向)。 但是,当将另一个ViewController推入堆栈时,这个方法不会在推送的ViewController上被调用(支持除了倒置以外的所有方向)。
我通过在“viewDidLoad”方法中调用“[self supportedInterfaceOrientations]”来解决了这个问题,但我认为这并不是解决问题的好方法。
希望你能在这个问题上给我帮助。
以下是我在第二个viewController中实现的代码。
我希望这篇文章可以帮助其他遇到相同问题的人。
问题如下: 我有一个自定义的UINavigationController,在创建它时会调用rootViewController上的“supportedInterfaceOrientations”方法(仅支持纵向)。 但是,当将另一个ViewController推入堆栈时,这个方法不会在推送的ViewController上被调用(支持除了倒置以外的所有方向)。
我通过在“viewDidLoad”方法中调用“[self supportedInterfaceOrientations]”来解决了这个问题,但我认为这并不是解决问题的好方法。
希望你能在这个问题上给我帮助。
以下是我在第二个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
方法。
- (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];
}
}
}
我希望这篇文章可以帮助其他遇到相同问题的人。