Module: Loco::Resizable
- Included in:
- Button, DatePicker, ImageView, Label, PickerView, ProgressView, ScrollView, Slider, TableView, TextView, Toolbar, View, WebView
- Defined in:
- lib/motion-loco/resizable.rb
Instance Attribute Summary collapse
-
#bottom ⇒ Integer
The position of the bottom edge, relative to the superview’s bottom edge.
-
#height ⇒ Integer
The height of the view.
-
#left ⇒ Integer
The position of the left edge, relative to the superview’s left edge.
-
#parent_view ⇒ Object
(also: #parentView)
Returns the value of attribute parent_view.
-
#right ⇒ Integer
The position of the right edge, relative to the superview’s right edge.
-
#top ⇒ Integer
The position of the top edge, relative to the superview’s top edge.
-
#width ⇒ Integer
The width of the view.
Instance Method Summary collapse
-
#initWithFrame(frame) ⇒ Object
Create new instance from a hash of properties with values.
-
#refresh_layout(superview = nil) ⇒ Object
Refresh the layout based on bottom, left, right, top, and superview.
- #view_setup ⇒ Object
- #viewSetup ⇒ Object
-
#willMoveToSuperview(superview) ⇒ Object
Fires when the superview changes.
Instance Attribute Details
#bottom ⇒ Integer
The position of the bottom edge, relative to the superview’s bottom edge.
11 12 13 |
# File 'lib/motion-loco/resizable.rb', line 11 def bottom @bottom end |
#height ⇒ Integer
The height of the view.
19 20 21 |
# File 'lib/motion-loco/resizable.rb', line 19 def height @height end |
#left ⇒ Integer
The position of the left edge, relative to the superview’s left edge.
28 29 30 |
# File 'lib/motion-loco/resizable.rb', line 28 def left @left end |
#parent_view ⇒ Object Also known as: parentView
Returns the value of attribute parent_view.
4 5 6 |
# File 'lib/motion-loco/resizable.rb', line 4 def parent_view @parent_view end |
#right ⇒ Integer
The position of the right edge, relative to the superview’s right edge.
37 38 39 |
# File 'lib/motion-loco/resizable.rb', line 37 def right @right end |
#top ⇒ Integer
The position of the top edge, relative to the superview’s top edge.
46 47 48 |
# File 'lib/motion-loco/resizable.rb', line 46 def top @top end |
#width ⇒ Integer
The width of the view.
54 55 56 |
# File 'lib/motion-loco/resizable.rb', line 54 def width @width end |
Instance Method Details
#initWithFrame(frame) ⇒ Object
Create new instance from a hash of properties with values.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/motion-loco/resizable.rb', line 62 def initWithFrame(frame) if frame.is_a? Hash # Set the initial property values from the given hash super(CGRect.new) frame.each do |key, value| self.send("#{key}=", value) end else super(frame) end view_setup self end |
#refresh_layout(superview = nil) ⇒ Object
Refresh the layout based on bottom, left, right, top, and superview.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/motion-loco/resizable.rb', line 78 def refresh_layout(superview=nil) # The view can't be positioned without being added to the superview first. superview ||= self.superview return if superview.nil? # Determine the original size, position, and autoresizing mask that should be used. if self.top && self.bottom if self.left && self.right # FW, FH @origin_x = self.left @origin_y = self.top @size_height = superview.bounds.size.height - self.top - self.bottom @size_width = superview.bounds.size.width - self.left - self.right @autoresizing = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight elsif self.left && self.width # FH, FRM @origin_x = self.left @origin_y = self.top @size_height = superview.bounds.size.height - self.top - self.bottom @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin elsif self.right && self.width # FH, FLM @origin_x = superview.bounds.size.width - self.width - self.right @origin_y = self.top @size_height = superview.bounds.size.height - self.top - self.bottom @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin elsif self.width # FH, FLM, FRM @origin_x = (superview.bounds.size.width - self.width) / 2 @origin_y = self.top @size_height = superview.bounds.size.height - self.top - self.bottom @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin else # Needs More Params NSLog('%@<Loco::View> Not enough params to position and size the view.', self.class) end elsif self.top if self.left && self.right && self.height # FW, FBM @origin_x = self.left @origin_y = self.top @size_height = self.height @size_width = superview.bounds.size.width - self.left - self.right @autoresizing = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin elsif self.left && self.height && self.width # FBM, FRM @origin_x = self.left @origin_y = self.top @size_height = self.height @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin elsif self.right && self.height && self.width # FBM, FLM @origin_x = superview.bounds.size.width - self.width - self.right @origin_y = self.top @size_height = self.height @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin elsif self.height && self.width # FLM, FRM, FBM @origin_x = (superview.bounds.size.width - self.width) / 2 @origin_y = self.top @size_height = self.height @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleBottomMargin else # Needs More Params NSLog('%@<Loco::View> Not enough params to position and size the view.', self.class) end elsif self.bottom if self.left && self.right && self.height # FW, FTM @origin_x = self.left @origin_y = superview.bounds.size.height - self.height - self.bottom @size_height = self.height @size_width = superview.bounds.size.width - self.left - self.right @autoresizing = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin elsif self.left && self.height && self.width # FTM, FRM @origin_x = self.left @origin_y = superview.bounds.size.height - self.height - self.bottom @size_height = self.height @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin elsif self.right && self.height && self.width # FTM, FLM @origin_x = superview.bounds.size.width - self.width - self.right @origin_y = superview.bounds.size.height - self.height - self.bottom @size_height = self.height @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin elsif self.height && self.width # FLM, FRM, FTM @origin_x = (superview.bounds.size.width - self.width) / 2 @origin_y = superview.bounds.size.height - self.height - self.bottom @size_height = self.height @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleTopMargin else # Needs More Params NSLog('%@<Loco::View> Not enough params to position and size the view.', self.class) end elsif self.left && self.right && self.height # FW, FTM, FBM @origin_x = self.left @origin_y = (superview.bounds.size.height - self.height) / 2 @size_height = self.height @size_width = superview.bounds.size.width - self.left - self.right @autoresizing = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin elsif self.width && self.height if self.left # FTM, FBM, FRM @origin_x = self.left @origin_y = (superview.bounds.size.height - self.height) / 2 @size_height = self.height @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin elsif self.right # FTM, FBM, FLM @origin_x = superview.bounds.size.width - self.width - self.right @origin_y = (superview.bounds.size.height - self.height) / 2 @size_height = self.height @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin else # FTM, FBM, FLM, FRM @origin_x = (superview.bounds.size.width - self.width) / 2 @origin_y = (superview.bounds.size.height - self.height) / 2 @size_height = self.height @size_width = self.width @autoresizing = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin end else # Needs More Params NSLog('%@<Loco::View> Not enough params to position and size the view.', self.class) end # Warn of any possible conflicts if self.top && self.bottom && self.height NSLog('%@<Loco::View> `top`, `bottom`, and `height` may conflict with each other. Only two of the three should be set.', self.class) NSLog('%@<Loco::View> top: %@, bottom: %@, height: %@', self.class, self.top, self.bottom, self.height) end if self.left && self.right && self.width NSLog('%@<Loco::View> `left`, `right`, and `width` may conflict with each other. Only two of the three should be set.', self.class) NSLog('%@<Loco::View> left: %@, right: %@, width: %@', self.class, self.left, self.right, self.width) end if @origin_x && @origin_y && @size_width && @size_height && @autoresizing self.frame = [[@origin_x, @origin_y], [@size_width, @size_height]] self.autoresizingMask = @autoresizing end # Update the subviews self.subviews.each do |view| view.refresh_layout(self) if view.is_a? Resizable end end |
#view_setup ⇒ Object
239 240 241 |
# File 'lib/motion-loco/resizable.rb', line 239 def view_setup viewSetup end |
#viewSetup ⇒ Object
243 244 245 |
# File 'lib/motion-loco/resizable.rb', line 243 def viewSetup # Override #view_setup or #viewSetup to customize the view end |
#willMoveToSuperview(superview) ⇒ Object
Fires when the superview changes.
248 249 250 251 |
# File 'lib/motion-loco/resizable.rb', line 248 def willMoveToSuperview(superview) self.parentView = superview refresh_layout(superview) end |