我在导航 Controller 中添加了三个 View Controller 。第一个和第二个 View Controller 应该支持两个方向,但第三个 View Controller 只支持横向模式。但是当我以纵向模式从第二个 View Controller 导航到第三个 View Controller 时,它以纵向模式显示。我该如何纠正这个问题?我需要第三个 View Controller 来仅支持横向。
最佳答案
这是一个 iOS 6 的答案。
要使 UINavigationController 尊重其子项的旋转首选项,请将其子类化并覆盖以下内容:
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
这在创建新的 UINavigationController 和弹回早期的 View Controller 时有效。更多信息在这里 - ViewController in UINavigationController orientation change
要在推送新 View Controller 时使其工作,请将其添加到您的子类中:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[super pushViewController:viewController animated:animated];
UIViewController *viewController = [[UIViewController alloc] init];
[self presentViewController:viewController animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
}
过渡有点不愉快,但它完成了工作。更多信息在这里 - Problem pushViewController from Landscape to Portrait
关于objective-c - 导航 Controller 中的方向变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13232141/