截至今天,以下作品。
app_delegate.rb :
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = AppController.alloc.initWithNibName(nil, bundle: nil)
@window.makeKeyAndVisible
true
end
end
AppController.rb (或任何你想给它的名字):
class AppController < UIViewController
def viewDidLoad
view.backgroundColor = UIColor.blackColor
@label = UILabel.alloc.initWithFrame( CGRectMake(100,100,200,50) )
@label.textColor = UIColor.whiteColor
@label.text = "Handling device orientation"
view.addSubview(@label)
end
def ipad?
return true if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
end
def shouldAutorotate
false
end
def supportedInterfaceOrientations
if ipad?
UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
else
UIInterfaceOrientationMaskPortrait
end
end
def preferredInterfaceOrientationForPresentation
ipad? ? UIInterfaceOrientationMaskLandscapeLeft : UIInterfaceOrientationMaskPortrait
end
end
AppController 中添加的标签只是给出了一个视觉提示。