首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rubymotion UIView方向

Rubymotion UIView方向
EN

Stack Overflow用户
提问于 2013-07-03 19:18:35
回答 3查看 393关注 0票数 0

我目前有一个用Rubymotion编写的ios应用程序。我正在尝试将UIViewController设置为始终以纵向显示,而不是旋转为横向。我不能只在rakefile中指定纵向,因为我需要其他specify控制器的所有方向。下面是我的代码:

代码语言:javascript
复制
class ConfirmationController < UIViewController

def viewDidLoad
    super
    self.view.backgroundColor = UIColor.blueColor
end

def shouldAutorotate
  true
end

def supportedInterfaceOrientations
  UIInterfaceOrientationMaskPortrait
end

def preferredInterfaceOrientationForPresentation
  UIInterfaceOrientationMaskPortrait
end

正如你所看到的,我正在尝试设置我的preferredInterfaceOrientation,但当我的设备旋转时,它仍然改变为横向。有关于如何用Rubymotion设置这个的想法吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-10-07 04:56:05

经过研究,我发现问题出在UINavigationController就是rootView。我必须添加一个继承自UINavigationController的命名控制器,然后覆盖默认的UINavigation设置以根据topViewController进行更改。

AppDelegate.rb

代码语言:javascript
复制
class TopNavController < UINavigationController

  def supportedInterfaceOrientations
    self.topViewController.supportedInterfaceOrientations
  end

  def preferredInterfaceOrientationForPresentation
    self.topViewController.preferredInterfaceOrientationForPresentation
  end
end

main_controller = MainScreenController.alloc.initWithNibName(nil, bundle: nil)
@window.rootViewController= TopNavController.alloc.initWithRootViewController(main_controller)

UIViewController

代码语言:javascript
复制
def shouldAutorotate
  true
end

def supportedInterfaceOrientations
  UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
end

def preferredInterfaceOrientationForPresentation
  UIInterfaceOrientationLandscapeLeft
end
票数 0
EN

Stack Overflow用户

发布于 2013-09-03 23:14:16

来自Rubymotion developer center

支持的接口方向。值必须是由以下一个或多个符号组成的数组::portrait、:landscape_left、:landscape_right和:portrait_upside_down。默认值为:portrait、:landscape_left、:landscape_right。

如果您需要锁定整个应用程序的横向方向,可以在Rakefile中设置interface_orientations,在

代码语言:javascript
复制
Motion::Project::App.setup do |app|
  app.name = 'Awesome App'
  app.interface_orientations = [:landscape_left,:landscape_right]
end
票数 3
EN

Stack Overflow用户

发布于 2013-07-03 20:38:16

preferredInterfaceOrientation不是一个属性,它是一个你必须实现的方法,用来改变你视图的行为。

因此,您应该删除设置preferredInterfaceOrientation的行,并在ViewController中添加类似以下内容:

代码语言:javascript
复制
class ConfirmationController < UIViewController
    ...
    ...

    def supportedInterfaceOrientations
        UIInterfaceOrientationMaskLandscape
    end

    def preferredInterfaceOrientationForPresentation
        UIInterfaceOrientationLandscapeRight
    end

    ...
    ...
end

有关其工作原理的详细信息,请查看Apple's documentation

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17446555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档