通过Rubymotion中的设备更改设备方向设置

时间:2013-07-11 07:01:07

标签: ios rubymotion

我有一个使用Rubymotion的通用应用程序,iPhone版本和iPad版本之间的UI设置差别很大。

主要是,在iPhone中它只支持肖像,iPad只支持横向。

我想这样做,如果可能的话,在Rakefile上设置一些东西,据我所知,替代方法是在delagate方法中做一些事情,但如果可能的话,我想在设置中设置方向设置文件。

Motion::Project::App.setup do |app|
  #app settings
  app.name = 'xxxxx'
  app.version = "0.xxxx"
  app.device_family = [:iphone, :ipad]
  app.interface_orientations = [:portrait]
end

编辑:

关于Jamon的答案是如何解决的一些更新。 如果在UINavigation中使用shouldAutorotate返回false会导致iPad版本出现奇怪现象,部分iPad版本将其视图内容显示为纵向,即使方向设置为横向,当我为shouldAutorotate返回true时,它仍然有效。

2 个答案:

答案 0 :(得分:2)

据我所知,你不能在你的Rakefile中做到这一点。您需要指定提供两个方向,然后以编程方式告诉iOS是否支持方向。

您的UIViewControllers和/或UINavigationController应如下所示:

def ipad?
  NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].include?("2")
end

def shouldAutorotate
  false # I think?
end

def supportedInterfaceOrientations
  if ipad?
    UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
  else
    UIInterfaceOrientationMaskPortrait
  end      
end

def preferredInterfaceOrientationForPresentation
  ipad? ? UIInterfaceOrientationMaskLandscapeLeft : UIInterfaceOrientationMaskPortrait
end

没有测试过这段代码,但过去我使用过类似的代码。您可以使用三元(就像我在上一个方法中所做的那样)或常规if

答案 1 :(得分:0)

截至今天,以下工作。

app_delegate.rb:

function ghost(){
        while (true){

        e1.style.top = Math.round(Math.random() * document.body.scrollHeight) + 'px';
        document.body.appendChild(e1);

        }

        }
<body  onload="gameLoop();" onkeydown="" onkeyup="moveSelection(event)"  onload="ghost();">

AppController.rb(或您想要给它的任何名称):

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window                       = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
    @window.rootViewController    = AppController.alloc.initWithNibName(nil, bundle: nil)
    @window.makeKeyAndVisible
    true
  end
end

AppController中添加的标签只是提供了一个关于它的视觉提示。

相关问题