我试图根据用户在我的应用程序中的位置来定义支持的方向,但我很难做到这一点。
到目前为止,我发现我应该使用 iOS6 中现在支持的supportedInterfaceOrientationsForWindow: 和shouldAutorotate 方法,但是当我在UIViewController 中定义它们时,这两种方法都不会被调用。
这就是我的代码的样子
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientationsForWindow {
return UIInterfaceOrientationMaskPortrait;
}
在我的目标摘要支持的方向中,我取消选择了所有选项..我想我只需在每个 View Controller 中定义支持的方向...我想知道这是否是正确的做法?
现在我已经读到我想要做的事情取决于我的应用程序的结构,所以在这里我将概述我的应用程序。
- 主 UIViewController(3 个按钮带您前往(3 个不同的 navigationControllerView),错误!只有一个 navigationController...抱歉,自从我查看此代码以来已经很长时间了。)
- 辅助 UIViewController(保存导航 Controller )
- 其他 UIViewController(出现在辅助导航 Controller 中)
我希望导航 Controller 堆栈中的每个 ViewController 直到最后一个 ViewController 都以纵向显示。 NavigationController 中的最后一个 View 是一个特殊 View ,需要能够根据需要向左或向右旋转其方向。
我想知道这是否可能,如果可以,为什么我上面的代码不能工作/被调用。
任何帮助将不胜感激。
//更新问题回复:
RootView加载(三个按钮,这里是选择按钮加载包含导航 Controller 的View时调用的方法)
- (IBAction)buttonClick: (UIButton *) sender
{
//..
// v ----->
if ([sender isEqual:vUIButton]) {
VSearchViewController *vSearchViewController = [[VSearchViewController alloc] initWithNibName:@"VSearchViewController" bundle:nil];
[self.navigationController pushViewController:vehicalSearchViewController animated:YES];
}
//..
}
然后在 VSearchViewController 中,我将新 View 加载到 UINavigation 堆栈上,如下所示
//..
FModelsViewController *fModelsViewController = [[FModelsViewController alloc] initWithNibName:@"FModelsViewController" bundle:nil];
// Sets the back button for the new view that loads (this overrides the usual parentview name with "Back")
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil];
[self.navigationController pushViewController:fModelsViewController animated:YES];
//..
因此,在审查中,我已经在 appDelegate 中设置了导航 Controller ,并且我的应用程序中的所有 View 都在 navigationStack 上...我错误地说有 3 个 NavigationController。只有一个,每个 View 都添加到堆栈.. 抱歉.. 自从我查看这段代码以来已经过去了一年半..
最佳答案
你在iOS6上运行上面的代码吗?这些方法只会在 iOS6 上调用。
也许您可以发布一些代码来更好地说明如何转换到这些 viewController,以便我们可以更好地理解 View 层次结构。
您可能想查看 UIViewController 的 addChildViewController:
方法。
关于ios - shouldAutorotate 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15396844/