Created
April 5, 2013 06:03
-
-
Save hboon/5316998 to your computer and use it in GitHub Desktop.
Implementing mixed-orientation in RubyMotion for iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#In Rakefile, set something like app.interface_orientations = [:portrait, :landscape_left, :landscape_right] | |
class AppDelegate | |
def application(application, didFinishLaunchingWithOptions:launchOptions) | |
application.setStatusBarStyle(UIStatusBarStyleBlackOpaque, animated:true) | |
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) | |
@window.rootViewController = NavigationController.alloc.initWithRootViewController(PortraitViewController.alloc.init) | |
@window.makeKeyAndVisible | |
true | |
end | |
end | |
#The UINavigationController subclass forwards to topViewController. | |
class NavigationController < UINavigationController | |
#####Orientation | |
def shouldAutorotate | |
self.topViewController.shouldAutorotate | |
end | |
def supportedInterfaceOrientations | |
self.topViewController.supportedInterfaceOrientations | |
end | |
end | |
#This is portrait only | |
class PortraitViewController < UIViewController | |
def initWithNibName(nibName, bundle:nibBundle) | |
super(nibName, nibBundle) | |
self.view.backgroundColor = UIColor.blueColor | |
b = UIButton.buttonWithType(UIButtonTypeRoundedRect) | |
b.frame = [[60, 100], [200, 20]] | |
b.setTitle('Show VC that rotates', forState:UIControlStateNormal) | |
b.addTarget(self, action:'click', forControlEvents:UIControlEventTouchUpInside) | |
self.view.addSubview(b) | |
self | |
end | |
def click | |
vc = PortraitAndLandscapeViewController.new | |
self.navigationController.pushViewController(vc, animated:true) | |
end | |
#####Orientation | |
def shouldAutorotate | |
true | |
end | |
def supportedInterfaceOrientations | |
UIInterfaceOrientationMaskPortrait | |
end | |
end | |
class PortraitAndLandscapeViewController < UIViewController | |
def initWithNibName(nibName, bundle:nibBundle) | |
super(nibName, nibBundle) | |
self.view.backgroundColor = UIColor.greenColor | |
self | |
end | |
#####Orientation | |
def shouldAutorotate | |
true | |
end | |
def supportedInterfaceOrientations | |
UIInterfaceOrientationMaskAllButUpsideDown | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment