Sha256: 52929a642a438315b2eff6acea610221015ce9b419d0e76bfbda60433522e7aa

Contents?: true

Size: 1.87 KB

Versions: 28

Compression:

Stored size: 1.87 KB

Contents

# @requires MotionKit::BaseLayout
module MotionKit
  class BaseLayout

    # This method is used to check the orientation.  On an ipad, this method
    # returns true for :portrait if the device is "upside down", but it returns
    # false in the same situation on an iphone.
    def orientation?(value)
      if target.is_a?(UIView) && target.nextResponder && target.nextResponder.is_a?(UIViewController)
        interface_orientation = target.nextResponder.interfaceOrientation
      else
        interface_orientation = UIApplication.sharedApplication.statusBarOrientation
      end

      return case value
      when :portrait
        if ipad?
          interface_orientation == UIInterfaceOrientationPortrait || interface_orientation == UIInterfaceOrientationPortraitUpsideDown
        else
          interface_orientation == UIInterfaceOrientationPortrait
        end
      when :upright, UIInterfaceOrientationPortrait
        interface_orientation == UIInterfaceOrientationPortrait
      when :landscape
        interface_orientation == UIInterfaceOrientationLandscapeLeft || interface_orientation == UIInterfaceOrientationLandscapeRight
      when :landscape_left, UIInterfaceOrientationLandscapeLeft
        interface_orientation == UIInterfaceOrientationLandscapeLeft
      when :landscape_right, UIInterfaceOrientationLandscapeRight
        interface_orientation == UIInterfaceOrientationLandscapeRight
      when :upside_down, UIInterfaceOrientationPortraitUpsideDown
        interface_orientation == UIInterfaceOrientationPortraitUpsideDown
      end
    end

    [:portrait, :upright, :upside_down, :landscape, :landscape_left, :landscape_right].each do |orientation|
      define_method("#{orientation}?") do
        return orientation?(orientation)
      end
      define_method(orientation) do |&block|
        if orientation?(orientation)
          yield
        end
      end
    end

  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
motion-kit-0.16.0 lib/motion-kit-ios/helpers/layout_orientation.rb
motion-kit-0.15.0 lib/motion-kit-ios/helpers/layout_orientation.rb
motion-kit-0.14.2 lib/motion-kit-ios/helpers/layout_orientation.rb
motion-kit-0.14.1 lib/motion-kit-ios/helpers/layout_orientation.rb
motion-kit-0.14.0 lib/motion-kit-ios/helpers/layout_orientation.rb
motion-kit-0.13.0 lib/motion-kit-ios/helpers/layout_orientation.rb
motion-kit-0.12.0 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.11.2 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.11.1 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.11.0 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.10.11 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.10.10 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.10.9 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.10.8 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.10.7 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.10.6 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.10.5 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.10.4 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.10.3 lib/motion-kit-ios/layouts/layout_orientation.rb
motion-kit-0.10.2 lib/motion-kit-ios/layouts/layout_orientation.rb