Skip to content

Instantly share code, notes, and snippets.

@sxross
Last active December 16, 2015 02:59
Show Gist options
  • Save sxross/5366148 to your computer and use it in GitHub Desktop.
Save sxross/5366148 to your computer and use it in GitHub Desktop.
This RubyMotion project shows an iPad app that doesn't seem to respond to upside down orientation. To build just: rake device_family=ipad
module Orientation
def ipad?
UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
end
end
class AppDelegate
include Orientation
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = window
@window.makeKeyAndVisible
true
end
def window
@window ||= begin
w = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
if ipad?
w.rootViewController = MainView.alloc.initWithText "Demo iPad"
else
w.rootViewController = MainView.alloc.initWithText "Demo iPhone"
end
w
end
end
end
class MyUIViewController < UIViewController
include Orientation
def willRotateToInterfaceOrientation(orientation, duration:duration)
super
puts "willRotateToInterfaceOrientation #{orientation}"
puts "device is ipad: #{ipad?} comparing orientation #{orientation} against upside-down #{UIInterfaceOrientationPortraitUpsideDown}"
result = true if ipad? or
orientation != UIInterfaceOrientationPortraitUpsideDown
puts "calculated #{result}"
result
end
end
class MainView < MyUIViewController
def initWithText(text)
initWithNibName nil, bundle:nil
@text = text
self
end
def viewDidAppear(animated)
super
self.view.backgroundColor = UIColor.whiteColor
@label ||= UILabel.alloc.initWithFrame [[10, 10], [100, 100]]
@label.text = @text
self.view.addSubview @label
end
def willRotateToInterfaceOrientation(orientation, duration:duration)
self.view.setNeedsLayout if super
end
end
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'foo'
app.device_family = [:iphone, :ipad]
interface_orientations = [:portrait, :landscape_left, :landscape_right, :portrait_upside_down]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment