2013-07-03 74 views
0

我目前有一個ios應用程序,我正在寫Rubymotion。我試圖設置一個UIViewController來縱向顯示,而不是旋轉到橫向。我不僅可以在我的rakefile中指定縱向,因爲我需要其他uiviewcontrollers的所有方向。請參閱下面的我的代碼:Rubymotion UIView方向

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設置的想法?

回答

0

做研究,我發現那裏的問題,從是的UINavigationController來了之後作爲rootView。我不得不添加一個從UINavigationController繼承的命名控制器,然後根據topViewController覆蓋默認的UINavigation設置以進行更改。

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 
1

preferredInterfaceOrientation不是一個屬性,它是一種你必須實現的方法,以改變你的視圖的行爲。

所以,你應該刪除,設置preferredInterfaceOrientation行,並添加這樣的事情在你的ViewController:

class ConfirmationController < UIViewController 
    ... 
    ... 

    def supportedInterfaceOrientations 
     UIInterfaceOrientationMaskLandscape 
    end 

    def preferredInterfaceOrientationForPresentation 
     UIInterfaceOrientationLandscapeRight 
    end 

    ... 
    ... 
end 

要詳細瞭解如何工作,看看Apple's documentation

3

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