2

我的应用程序具有以下主要结构:UITabBarController,其中每个选项卡都承载一个 UINavigationController,它根据用户交互推送视图。几乎所有的应用程序都是纵向的,除了一些特定的部分。

push我想要的行为是在其中一个部分(比如说地图)时具有横向。在该地图中,用户可以返回纵向。当他返回主菜单时,他应该返回纵向(此处不允许横向)。我不介意他是否暂时在风景中。

这是我的 UITabBarController 子类中的一些代码:

- (BOOL)shouldAutorotate
{
    return [self.selectedViewController shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return [self.selectedViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}

我在 UINavigationController 中使用相同的代码,在特定菜单中,我有这个:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (BOOL)shouldAutorotate
{
    if (!UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
        return NO;

    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

这种行为几乎一直有效。当菜单的方向是横向并且用户旋转他的设备时,他会回到纵向,但不能回到横向。

我的问题是:偶尔,状态栏会旋转,但视图控制器不会。 (见图)每次,shouldAutorotate被调用并返回正确的值(即它返回 YES 但不自动旋转)。

我知道这是在扩展 SDK,但我很想一直做这项工作。有什么提示吗?

在此处输入图像描述

4

0 回答 0