代码之家  ›  专栏  ›  技术社区  ›  Cocoa Dev

仅适用于iPhone或iPad的横向模式

  •  36
  • Cocoa Dev  · 技术社区  · 15 年前

    我想创建一个不使用纵向模式的应用程序。

    我不确定是否需要编辑plist或除了plist之外还有代码

    4 回复  |  直到 9 年前
        1
  •  47
  •   Justin Gregoire    15 年前

    Code found here

    以横向模式启动

    iPhone操作系统中的应用程序通常 以纵向模式启动以匹配 主屏幕的方向。如果你 有一个应用程序同时运行 纵向和横向模式,您的 应用程序应始终在 纵向模式开始,然后让 其视图控制器旋转 根据需要的接口 设备的方向。如果你的 应用程序以横向模式运行 但是,您必须执行 以下步骤使其在 最初是横向的。

    • 在applications info.plist文件中,添加 UIInterfaceOrientation
      并将其值设置为
      横向模式。用于景观
      方向,可以设置值
      这把钥匙的
      UIInterfaceOrientationLandscapeLeft

      UIInterfaceOrientationLandscapeRight.

    • 以横向模式布置您的视图,并确保 设置自动调整大小选项 正确地。

    • 覆盖视图控制器 shouldAutorotateToInterfaceOrientation: 方法并返回Yes
      所需的景观方向和否
      用于纵向。

        2
  •  29
  •   Aleksander Azizi VikashVikash SinghSingh    9 年前

    使应用程序横向模式 只有 ,您应该使用“支持的接口方向”。 ( Targets -> YourApp -> Supported Interface Orientations -> Landscape Left & Right )

    Supported Interface Orientations

    您还应该在应用程序中设置应用程序的方向 Info.plist 文件(文件) Info.plist file )通过附加 Supported interface orientations 带值的键 Landscape (left home button) Landscape (right home button) . row's

    你可以用 willRotateToInterfaceOrientation 和/或 didRotateFromInterfaceOrientation 处理方向更改。


    shouldAutorotateToInterfaceOrientation 已从中弃用 IOS 6 然后出去。

    返回 UIDeviceOrientationLandscapeLeft/Right 对于 应注意面间方向 应该让你的应用“横向”的:

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

    也可以更改应用程序 信息列表 View Orientation (如上所述)。


    此外,我建议将视图的方向更改为 Landscape 属性检查器 . landscape

        3
  •  26
  •   fedmest    13 年前

    你也可以把它缩短到

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }
    
        4
  •  10
  •   jrtc27    15 年前

    编辑plist以仅支持横向,然后确保在每个uiviewcontroller/uitabbar等中 shouldAutoRotateToInterfaceOrientation , the return return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); .