2013-07-03 1 views
0

현재 Rubyotion에 쓰고있는 ios 앱이 있습니다. 항상 세로 방향으로 표시하고 가로 방향으로 회전하지 않도록 UIViewController를 설정하려고합니다. 나는 다른 raviewcontroller를 위해 모든 orientaitons을 필요로하므로 rakefile에서 세로 방향을 지정할 수 없습니다. 내 코드는 아래를 참조하십시오 :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

에서, 당신의 Rakefile에서 interface_orientations을 설정할 수 있습니다 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 
3

에서 봐,이 작동하는 방법에 대한 자세한 내용은

class ConfirmationController < UIViewController 
    ... 
    ... 

    def supportedInterfaceOrientations 
     UIInterfaceOrientationMaskLandscape 
    end 

    def preferredInterfaceOrientationForPresentation 
     UIInterfaceOrientationLandscapeRight 
    end 

    ... 
    ... 
end 

:

그래서, 당신은 preferredInterfaceOrientation을 설정하는 행을 제거하고의 ViewController에서 같은 것을 추가해야

지원되는 인터페이스 방향. 값은 다음 기호 중 하나 이상의 배열이어야합니다 : : portrait, : landscape_left, : landscape_right 및 : portrait_upside_down. 기본값은 [: portrait, : landscape_left, : landscape_right]입니다.

당신이 전체 앱 가로의 방향을 고정해야하는 경우에는 문제가 UINavigationController가 있었다에서 온 내가 찾은 연구를 수행 한 후

Motion::Project::App.setup do |app| 
    app.name = 'Awesome App' 
    app.interface_orientations = [:landscape_left,:landscape_right] 
end