module BubbleWrap::Device::Screen

Public Instance Methods

height() click to toggle source

The height of the device's screen. The real resolution is dependant on the scale factor (see `retina?`) but the coordinate system is in non-retina pixels. You can get pixel accuracy by using half-coordinates. This is a Float

# File motion/core/device/ios/screen.rb, line 73
def height
  UIScreen.mainScreen.bounds.size.height
end
height_for_orientation(o=orientation) click to toggle source

The same as `.width` and `.height` but compensating for screen rotation (which can do your head in).

# File motion/core/device/ios/screen.rb, line 88
def height_for_orientation(o=orientation)
  return width if (o == :landscape_left) || (o == :landscape_right)
  height
end
interface_orientation(device_orientation=UIDevice.currentDevice.orientation, fallback=true) click to toggle source

Figure out the current orientation of the interface @return [:portrait, :portrait_upside_down, :landscape_left, :landscape_right]

# File motion/core/device/ios/screen.rb, line 40
def interface_orientation(device_orientation=UIDevice.currentDevice.orientation, fallback=true)
  case device_orientation
  when UIInterfaceOrientationPortrait then :portrait
  when UIInterfaceOrientationPortraitUpsideDown then :portrait_upside_down
  when UIInterfaceOrientationLandscapeLeft then :landscape_left
  when UIInterfaceOrientationLandscapeRight then :landscape_right
  else
    # In some cases, the accelerometer can't get an accurate read of orientation so we fall back on the orientation of
    # the status bar.
    if fallback && (device_orientation != UIApplication.sharedApplication.statusBarOrientation)
      orientation(UIApplication.sharedApplication.statusBarOrientation)
    else
      :unknown
    end
  end
end
orientation(device_orientation=UIDevice.currentDevice.orientation, fallback=true) click to toggle source

Figure out the current physical orientation of the device @return [:portrait, :portrait_upside_down, :landscape_left, :landscape_right, :face_up, :face_down, :unknown]

# File motion/core/device/ios/screen.rb, line 19
def orientation(device_orientation=UIDevice.currentDevice.orientation, fallback=true)
  case device_orientation
  when UIDeviceOrientationPortrait then :portrait
  when UIDeviceOrientationPortraitUpsideDown then :portrait_upside_down
  when UIDeviceOrientationLandscapeLeft then :landscape_left
  when UIDeviceOrientationLandscapeRight then :landscape_right
  when UIDeviceOrientationFaceUp then :face_up
  when UIDeviceOrientationFaceDown then :face_down
  else
    # In some cases, the accelerometer can't get an accurate read of orientation so we fall back on the orientation of
    # the status bar.
    if fallback && (device_orientation != UIApplication.sharedApplication.statusBarOrientation)
      orientation(UIApplication.sharedApplication.statusBarOrientation)
    else
      :unknown
    end
  end
end
retina?(screen=UIScreen.mainScreen) click to toggle source

Certifies that the device running the app has a Retina display @return [TrueClass, FalseClass] true will be returned if the device has a Retina display, false otherwise.

# File motion/core/device/ios/screen.rb, line 9
def retina?(screen=UIScreen.mainScreen)
  if screen.respondsToSelector('displayLinkWithTarget:selector:') && screen.scale == 2.0
    true
  else
    false
  end
end
width() click to toggle source

The width of the device's screen. The real resolution is dependant on the scale factor (see `retina?`) but the coordinate system is in non-retina pixels. You can get pixel accuracy by using half-coordinates. This is a Float

# File motion/core/device/ios/screen.rb, line 63
def width
  UIScreen.mainScreen.bounds.size.width
end
width_for_orientation(o=orientation) click to toggle source

The same as `.width` and `.height` but compensating for screen rotation (which can do your head in).

# File motion/core/device/ios/screen.rb, line 80
def width_for_orientation(o=orientation)
  return height if (o == :landscape_left) || (o == :landscape_right)
  width
end