1

我在我的应用程序中使用 UINavigationController 并且我的第一个控制器名为A,它仅限于 portrite 并且在我的 A控制器中有一个按钮。单击该按钮后,我正在为另一个名为B的视图控制器创建实例。在为 BI 创建实例后,我使用以下方法以模态方式呈现

[self presentViewController:BInstance animated:YES completion:^{
            NSLog(@"completed");
        }];

我的 B 控制器可以支持所有方向,这是预期的,直到 ios5.1 和更早版本。现在我正在尝试使用 Xcode4.5 在 ios6 上运行我的项目,它没有旋转我期待解决这个问题,我发现一些关于shouldAutorotateToInterfaceOrientation:方法的博客从最新的 ios6 中被弃用。我也使用了替代品

-(BOOL)shouldAutorotate{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}

但仍然没有太多预期的结果。

问题:是什么让我的B控制器适用于所有方向,即使我的父A仅适用于 portrite。

在此先感谢您的所有建议/建议对此有用。

4

1 回答 1

5

首先,在 AppDelegate 中,这样写。这是非常重要的

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     return (UIInterfaceOrientationMaskAll);
}

然后,对于只需要PORTRAIT模式的 UIViewControllers,编写这些函数

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait);
}

对于也需要LANDSCAPE的 UIViewController,将遮罩更改为全部。

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskAllButUpsideDown);
    //OR return (UIInterfaceOrientationMaskAll);
}

现在,如果您想在方向更改时进行一些更改,请使用此功能。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{

}
于 2012-10-03T10:27:59.630 回答