Module: BubbleWrap::Device::Screen

Defined in:
motion/core/device/screen.rb

Class Method Summary collapse

Class Method Details

.heightObject

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



48
49
50
# File 'motion/core/device/screen.rb', line 48

def height
  UIScreen.mainScreen.bounds.size.height
end

.height_for_orientation(o = orientation) ⇒ Object

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



63
64
65
66
# File 'motion/core/device/screen.rb', line 63

def height_for_orientation(o=orientation)
  return width if (o == :landscape_left) || (o == :landscape_right) 
  height
end

.orientation(device_orientation = UIDevice.currentDevice.orientation) ⇒ :portrait, ...

Figure out the current physical orientation of the device

Returns:

  • (:portrait, :portrait_upside_down, :landscape_left, :landscape_right, :face_up, :face_down, :unknown)


19
20
21
22
23
24
25
26
27
28
29
30
# File 'motion/core/device/screen.rb', line 19

def orientation(device_orientation=UIDevice.currentDevice.orientation)
  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
    :unknown
  end
end

.retina?(screen = UIScreen.mainScreen) ⇒ TrueClass, FalseClass

Certifies that the device running the app has a Retina display

Returns:

  • (TrueClass, FalseClass)

    true will be returned if the device has a Retina display, false otherwise.



9
10
11
12
13
14
15
# File 'motion/core/device/screen.rb', line 9

def retina?(screen=UIScreen.mainScreen)
  if screen.respondsToSelector('displayLinkWithTarget:selector:') && screen.scale == 2.0
    true
  else
    false
  end
end

.widthObject

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



38
39
40
# File 'motion/core/device/screen.rb', line 38

def width
  UIScreen.mainScreen.bounds.size.width
end

.width_for_orientation(o = orientation) ⇒ Object

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



55
56
57
58
# File 'motion/core/device/screen.rb', line 55

def width_for_orientation(o=orientation)
  return height if (o == :landscape_left) || (o == :landscape_right) 
  width
end