【问题标题】:Disable portrait mode禁用人像模式
【发布时间】:2011-12-22 09:11:09
【问题描述】:

我正在开发一个 iPhone 应用程序,该应用程序只能在横向模式下工作。但是,当我旋转设备或模拟器时,viewContoller 的模式会从横向变为纵向。我希望 viewController 保持横向模式,尽管设备或模拟器是纵向的。我怎么能做到这一点?提前致谢。

【问题讨论】:

    标签: iphone objective-c ios ios4 landscape


    【解决方案1】:

    在您的视图控制器中覆盖此方法:

    // Override to allow orientations other than the default portrait orientation.
    -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientation, NO for other;
    }
    

    【讨论】:

    • OP 声明他不希望支持纵向模式,因此仅返回 YES 将无济于事。
    • 显然......我只是指出了他必须覆盖的方法。我没有写完整的代码...
    【解决方案2】:

    将此添加到您的ViewController.m

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
            return UIInterfaceOrientationIsLandscape(interfaceOrientation);   
    }
    

    【讨论】:

      【解决方案3】:

      更改 info_plist .. 支持的界面方向仅设置横向

      【讨论】:

      • 我有这一套,不过好像还不够。
      【解决方案4】:

      在你所有的 ViewController 中重写这个方法:

      - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
          // Return YES for supported orientations
          return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
                  interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
      

      }

      另见Only support for landscape Interface orientation

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-27
        • 2013-08-31
        • 1970-01-01
        • 1970-01-01
        • 2013-10-18
        • 2023-03-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多