在我的应用程序中,我有多个视图,一些视图需要支持纵向和横向,而其他视图只需要支持纵向.因此,在项目摘要中,我已经选择了所有方向.
以下代码用于在iOS 6之前禁用给定视图控制器上的横向模式:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)
由于在iOS6中不推荐使用shouldAutorotateToInterfaceOrientation,我将以上内容替换为:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMask.Portrait;
}
Run Code Online (Sandbox Code Playgroud)
当视图出现时我会正确调用此方法(我可以设置断点以确保这一点),但是界面仍然会旋转到横向模式,而不管我是否仅为纵向模式返回蒙版.我究竟做错了什么?
似乎目前无法构建一个每个视图具有不同方向要求的应用程序.它似乎只遵循项目摘要中指定的方向.
在我的mainwindow.xib中,我有一个navigationcontroller.在(作为子项)之上我有另一个viewcontroller(homeviewcontroller).
在笔尖中,我将窗口的rootviewcontroller设置为此导航控制器.
这部署到应用程序商店并完美运行.
自升级到ios6 sdk以来,我遇到了方向问题 - 基本上使用这种设计,在ios 6设备/模拟器中运行我的应用程序时,我的homeviewcontroller的supportedInterfaceOrientations方法不会被调用.
为了解决这个问题,我需要将homeviewcontroller设置为窗口的rootviewcontroller但是这不是我想要的 - 我需要navigationcontroller.
如何解决ios6中这个恼人的错误?
更新:
我也尝试过以编程方式执行此操作 - 它仍然无法正常工作.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
HomeViewController *homeVC = [[HomeViewController alloc]init];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:homeVC];
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)