通用应用程序,iPhone 为纵向,iPad 为横向

Universal application with Portrait orientation for iPhone and Landscape orientation for iPad

我正在使用 Swift 创建通用应用程序。我使用了 Storyboard 和 Auto-Layouts。要求是创建一个通用应用程序,该应用程序仅支持 iPhone 的纵向方向和仅 iPad.

的横向方向

我已经为 iPhone 开发了 UI,现在我将开始 iPad UI。

此外,为 iPhone 创建的 UI 与为 iPad 创建的 UI 不同,两者 UI 完全不同。

我正在考虑为 iPhone 和 iPad 创建单独的故事板。有什么合适的方法可以做到这一点吗?

如果您仅将应用程序部署到 iOS 8,那么我会使用一个故事板。使用一个屏幕更简单。这是一篇很棒的教程 link。 http://www.raywenderlich.com/83276/beginning-adaptive-layout-tutorial
如果你像我一样想要将目标降低到 iOS 6,那么我会使用单独的故事板。无论您决定使用什么,一定要坚持使用自动布局。
别忘了我们必须开始支持 64 位。
祝你好运!

转到 info.plist 文件并添加一个包含键 "Supported interface orientations (iPhone)" 的数组,并在其中添加以下值:

  1. 纵向(底部主页按钮)

同样,添加另一个数组"Supported interface orientations (iPad)"并添加以下内容:

  1. 纵向(底部主页按钮)
  2. 横向(左主页按钮)
  3. 横向(右主页按钮)

见下文:

如果您想为特定的 ViewController 设置此设置(在 iPad 上允许全部但在 iPhone 上只允许纵向设置)将此设置到您的 ViewController-class (Swift 4):

override var supportedInterfaceOrientations:UIInterfaceOrientationMask {
    return UIDevice.current.userInterfaceIdiom == .pad ? UIInterfaceOrientationMask.all : UIInterfaceOrientationMask.portrait
}