Skip to content

Instantly share code, notes, and snippets.

@hboon
Created April 5, 2013 06:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hboon/5316998 to your computer and use it in GitHub Desktop.
Save hboon/5316998 to your computer and use it in GitHub Desktop.
Implementing mixed-orientation in RubyMotion for iOS
#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