【问题标题】:Portrait in one viewController and landscape in another一个视图控制器中的纵向和另一个视图控制器中的横向
【发布时间】:2014-04-01 20:40:21
【问题描述】:

我有以下 ViewController:

InformationViewController 和 cardViewController。

如何确保 informationViewController 处于纵向模式且无法旋转。

那么cardViewController应该是横向模式,不能旋转。

如何在每个 viewController 中实现这一点。我现在已经在一般情况下激活了纵向,横向和横向

【问题讨论】:

  • 虽然下面的一些答案将帮助您回答这个问题,但我只是提供友好的提醒,这种事情是违反用户界面建议的。它提供了糟糕的用户体验,迫使用户在视图之间旋转设备,除非有非常明确和明确的需要。虽然您当然有可能对此有有效的用途,但只需重新考虑用例并确定您是否真的想要这个。

标签: ios iphone objective-c


【解决方案1】:

在信息视图控制器中

- (BOOL)shouldAutorotate

{

    return YES;
}


- (NSUInteger)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskPortrait;
}

在卡片视图控制器中

- (BOOL)shouldAutorotate

{

    return YES;
}


- (NSUInteger)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskLandscape;
}

注意:请务必在项目常规设置中勾选设备方向中的纵向和横向模式(部署信息)

【讨论】:

    【解决方案2】:

    在信息视图控制器中:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    

    在cardViewController中:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationLandscape);
    }
    

    【讨论】:

    • 是的,这会阻止视图控制器旋转到“禁止”方向。但是当其中一个被推到另一个或稍后弹回时,它不会使设备旋转视图。
    【解决方案3】:

    看看我对这个问题的回答: Force controllers to Change their orientation in Either Portrait or Landscape

    (但不要使用已弃用的方法。有更新的方法也可以使用。)

    很容易将视图控制器限制在某些方向。但是请参阅其他答案以了解如何强制设备实际旋转。 如果没有这个技巧:如果在设备处于横向时仅纵向视图控制器变得可见,那么无论您如何限制其支持的方向,它将以横向显示。

    【讨论】:

      猜你喜欢
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多