Class: UIViewController

Inherits:
Object
  • Object
show all
Includes:
Teacup::Controller, Teacup::Layout
Defined in:
lib/teacup-ios/core_extensions/ui_view_controller.rb

Instance Method Summary collapse

Methods included from Teacup::Controller

included, #layoutDidLoad, #stylesheet=, #teacupDidLoad

Methods included from Teacup::Layout

#auto, included, #layout, #stylesheet, #stylesheet=, #subview

Instance Method Details

#autorotateMaskObject

You can use this method in ‘supportedInterfaceOrientations`, and it will query the stylesheet for the supported orientations, based on what orientations are defined. At a minimum, to opt-in to this feature, you’ll need to define styles like ‘style :root, landscape: true`



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/teacup-ios/core_extensions/ui_view_controller.rb', line 56

def autorotateMask
  device = UIDevice.currentDevice.userInterfaceIdiom
  if view.stylesheet and view.stylesheet.is_a?(Teacup::Stylesheet) and view.stylename
    properties = view.stylesheet.query(view.stylename, self, nil)

    orientations = 0
    if properties.supports?(:portrait) or properties.supports?(:upside_up)
      orientations |= UIInterfaceOrientationPortrait
    end

    if device == UIUserInterfaceIdiomPhone
      # :portrait does not imply upside_down on the iphone
      if properties.supports?(:upside_down)
        orientations |= UIInterfaceOrientationPortraitUpsideDown
      end
    else
      # but does on the ipad
      if properties.supports?(:portrait) or properties.supports?(:upside_down)
        orientations |= UIInterfaceOrientationPortraitUpsideDown
      end
    end

    if properties.supports?(:landscape) or properties.supports?(:landscape_left)
      orientations |= UIInterfaceOrientationLandscapeLeft
    end

    if properties.supports?(:landscape) or properties.supports?(:landscape_right)
      orientations |= UIInterfaceOrientationLandscapeRight
    end

    if orientations == 0
      orientations |= UIInterfaceOrientationPortrait
    end
    return orientations
  end

  # returns the system default
  if device == UIUserInterfaceIdiomPhone
    return UIInterfaceOrientationMaskAllButUpsideDown
  else
    return UIInterfaceOrientationMaskAll
  end
end

#autorotateToOrientation(orientation) ⇒ Object

This method used to be useful for the ‘shouldAutorotateToOrientation` method, but the iOS 6 update deprecates that method. Instead, use the `supportedInterfaceOrientations` and return `autorotateMask`.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/teacup-ios/core_extensions/ui_view_controller.rb', line 12

def autorotateToOrientation(orientation)
  device = UIDevice.currentDevice.userInterfaceIdiom
  if view.stylesheet and view.stylesheet.is_a?(Teacup::Stylesheet) and view.stylename
    properties = view.stylesheet.query(view.stylename, self, orientation)

    # check for orientation-specific properties
    case orientation
    when UIInterfaceOrientationPortrait
      # portrait is "on" by default, must be turned off explicitly
      if properties.supports?(:portrait) == nil and properties.supports?(:upside_up) == nil
        return true
      end

      return (properties.supports?(:portrait) or properties.supports?(:upside_up))
    when UIInterfaceOrientationPortraitUpsideDown
      if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone
        # iphone must have an explicit upside-down style, otherwise this returns
        # false
        return properties.supports?(:upside_down)
      else
        # ipad can just have a portrait style
        return (properties.supports?(:portrait) or properties.supports?(:upside_down))
      end
    when UIInterfaceOrientationLandscapeLeft
      return (properties.supports?(:landscape) or properties.supports?(:landscape_left))
    when UIInterfaceOrientationLandscapeRight
      return (properties.supports?(:landscape) or properties.supports?(:landscape_right))
    end

    return false
  end

  # returns the system default
  if device == UIUserInterfaceIdiomPhone
    return orientation != UIInterfaceOrientationPortraitUpsideDown
  else
    return true
  end
end

#top_level_viewObject



107
108
109
# File 'lib/teacup-ios/core_extensions/ui_view_controller.rb', line 107

def top_level_view
  view
end

#viewDidLoadObject



5
6
7
# File 'lib/teacup-ios/core_extensions/ui_view_controller.rb', line 5

def viewDidLoad
  teacupDidLoad
end

#willAnimateRotationToInterfaceOrientation(orientation, duration: duration) ⇒ Object

restyles the view! be careful about putting styles in your stylesheet that you change in your controller. anything that might change over time should be applied in your controller using ‘style`



103
104
105
# File 'lib/teacup-ios/core_extensions/ui_view_controller.rb', line 103

def willAnimateRotationToInterfaceOrientation(orientation, duration:duration)
  view.restyle!(orientation)
end