【问题标题】:iPhone / iPad universal app orientationiPhone / iPad 通用应用程序方向
【发布时间】:2011-02-23 17:41:44
【问题描述】:

我正在开发通用应用程序。现在我想为这两种方式设置方向,当应用程序在 iPhone 上启动时,它以纵向模式打开,当应用程序在 iPad 上启动时,它以横向模式打开。

有可能吗?

【问题讨论】:

    标签: iphone ipad orientation


    【解决方案1】:
    - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
            return YES;
        } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
            return YES;
        }
    
        return NO;
    }
    

    【讨论】:

      【解决方案2】:
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        // The device is an iPad running iPhone 3.2 or later.
        // Rotate to landscape
      }
      else {
        // The device is an iPhone or iPod touch.
        // Rotate to portrait
      }
      

      How does one get UI_USER_INTERFACE_IDOM to work with iOS 3.2?

      【讨论】:

      • 正如@Emil 所暗示的,您可以在视图控制器中使用上述shouldAutorotateToInterfaceOrientation 方法来控制每个设备的方向。
      【解决方案3】:

      您也可以使用 [UIDevice currentDevice].model 或 [UIDevice currentDevice].systemName 来识别设备,然后在 shouldAutoRotate 方法中根据设备类型返回 interfaceOrientation ==UIInterfaceOrientationLandscapeLeft 用于 ipad 和 interfaceOrientation ==UIInterfaceOrientationPortrait 用于 iphone。

      【讨论】:

        【解决方案4】:

        您可以通过根据my answer here 向您的应用委托添加一些代码来做到这一点。

        Swift 代码:

        func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
            if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
                return Int(UIInterfaceOrientationMask.Portrait.rawValue)
            } else {
                return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue | UIInterfaceOrientationMask.LandscapeRight.rawValue)
            }
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-09-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-06-14
          相关资源
          最近更新 更多