0

我的视图层次结构是这样设置的。

UITabBarController
    |
    UINavigationController
    |  |
    |  UIViewController
    |
    UINavigationController
       |
       UIViewController

问题是我有一个仅在纵向中显示的 ViewController,只要我将设备转为横向,另一个 ViewController 就会被推到顶部,到目前为止它正在按预期工作。

我现在想要的是,只要我按下新弹出的 ViewController 上的后退按钮,旧的 ViewController 就会被强制为纵向,即使设备仍处于横向状态。
我已经尝试过使用过渡,但随后其他视图被搞砸了,并且不再正确识别那里的方向,导致混乱的视图移位。

4

3 回答 3

2

唯一对我有用的是使用

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

在我的 ViewController 中并用presentModalViewController呈现它。这迫使视图保持在横向。不完全是我想要的,但它成功了。

于 2012-04-25T13:44:01.277 回答
1

尝试将此添加到您的原始视图控制器:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) return YES;
    return NO;
}

这应该强制它仅以纵向显示。

于 2011-11-25T11:47:40.627 回答
1

下面的代码将强制视图进入横向模式,但前提是父视图控制器支持横向模式。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

如果要强制进入横向模式的视图的父视图控制器仅是纵向的,则必须创建一个新的新导航控制器。最简单的方法就是在模态视图中显示强制横向视图控制器。所以使用 presentModalViewController 而不是 pushViewController。

于 2012-06-08T14:26:48.710 回答