我目前有一个用Rubymotion编写的ios应用程序。我正在尝试将UIViewController设置为始终以纵向显示,而不是旋转为横向。我不能只在rakefile中指定纵向,因为我需要其他specify控制器的所有方向。下面是我的代码:
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设置这个的想法吗?
发布于 2014-10-07 04:56:05
经过研究,我发现问题出在UINavigationController就是rootView。我必须添加一个继承自UINavigationController的命名控制器,然后覆盖默认的UINavigation设置以根据topViewController进行更改。
AppDelegate.rb
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
def shouldAutorotate
true
end
def supportedInterfaceOrientations
UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
end
def preferredInterfaceOrientationForPresentation
UIInterfaceOrientationLandscapeLeft
end发布于 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,在
Motion::Project::App.setup do |app|
app.name = 'Awesome App'
app.interface_orientations = [:landscape_left,:landscape_right]
end发布于 2013-07-03 20:38:16
preferredInterfaceOrientation不是一个属性,它是一个你必须实现的方法,用来改变你视图的行为。
因此,您应该删除设置preferredInterfaceOrientation的行,并在ViewController中添加类似以下内容:
class ConfirmationController < UIViewController
...
...
def supportedInterfaceOrientations
UIInterfaceOrientationMaskLandscape
end
def preferredInterfaceOrientationForPresentation
UIInterfaceOrientationLandscapeRight
end
...
...
end有关其工作原理的详细信息,请查看Apple's documentation
https://stackoverflow.com/questions/17446555
复制相似问题