0

我有一个 iOS 通用应用程序,我需要使用它:

  • 适用于 iPad 的 LandscapeLeft 或 LandscapeRight

  • iPhone 人像

以 iPad 为例,我需要强制应用以横向模式打开,即使用户的设备处于纵向模式。当该应用程序仅适用于 iPad 并且 rakefile 使用此设置时,这是完美的:

app.interface_orientations = [:landscape_left, : landscape_right]

不幸的是,现在,删除它后,该应用程序默认以纵向模式显示。我试图通过覆盖 UIViewController.rb 中的以下方法来改变这一点。这适用于模拟器,但不适用于我的设备:

  def shouldAutorotate
    # Block AutoRotation if the interfaces is CORRECT
    # Else allow IT
    if Device.ipad? # BubbleWrap gem method 
      if App.shared.interfaceOrientation == UIInterfaceOrientationLandscapeLeft
        return false
      elsif App.shared.interfaceOrientation == UIInterfaceOrientationLandscapeRight
        return false
      else
        return true
      end
    elsif Device.iphone?
      if App.shared.interfaceOrientation == UIInterfaceOrientationPortrait
        return false
      else
        return true
      end
    end
  end

  def viewDidAppear(animated)
    # Change the orientation after the view Appeared
    if Device.ipad?
      App.shared.setStatusBarOrientation(UIInterfaceOrientationLandscapeLeft)
    elsif Device.iphone?
      App.shared.setStatusBarOrientation(UIInterfaceOrientationPortrait)
    end
  end

我尝试了很多解决方案,但似乎都没有按照我想要的方式工作。

谢谢,弗拉德

4

1 回答 1

0

为了尝试简化一切,您可以使用运动方案包装器,它可以让您为每个设备设置不同的设置,这意味着您可以回到简单的app.interface_orientations状态并避免所有的黑客行为。

于 2013-12-11T00:56:56.520 回答